Python 保存爬行动物捕捉网页
2023-09-27 14:27:02 时间
选址的桌面壁纸网站汽车主题:
下面的两个print打开调试期间
#print tag #print attrs
#!/usr/bin/env python import re import urllib2 import HTMLParser base = "http://desk.zol.com.cn" path = '/home/mk/cars/' star = '' def get_url(html): parser = parse(False) request = urllib2.Request(html) response = urllib2.urlopen(request) resp = response.read() parser.feed(resp) def download(url): content = urllib2.urlopen(url).read() format = '[0-9]*\.jpg'; res = re.search(format,url); print 'downloading:',res.group() filename = path+res.group() f = open(filename,'w+') f.write(content) f.close() class parse(HTMLParser.HTMLParser): def __init__(self,Index): self.Index = Index; HTMLParser.HTMLParser.__init__(self) def handle_starttag(self,tag,attrs): #print tag #print attrs if(self.Index): if not cmp(tag,'a'): if(len(attrs) == 4): if(attrs[0] ==('class','pic')): #print tag #print attrs new = base+attrs[1][1] print 'found a link:',new global star star = new get_url(new) else: if not cmp(tag,'img'): if(attrs[0] == ('id','bigImg')): #print tag #print attrs Image_url = attrs[1][1] print 'found a picture:',Image_url download(Image_url) if not cmp(tag,'a'): if (len(attrs) == 4): if (attrs[1] == ('class','next')): #print tag #print attrs next = base + attrs[2][1] print 'found a link:',next if (star != next): get_url(next) Index_url = 'http://desk.zol.com.cn/qiche/' con = urllib2.urlopen(Index_url).read() Parser_index = parse(True) Parser_index.feed(con)
唯一的缺点是,在网站上漂亮的壁纸桌面壁纸 。
。。
版权声明:本文博客原创文章,博客,未经同意,不得转载。
相关文章
- 利用Python实现 队列的算法
- 128 python高级 - ThreadLocal
- 初学指南| 用Python进行网页抓取
- 《精通Python网络爬虫:核心技术、框架与项目实战》——3.4 网页分析算法
- 雾里看花之 Python Asyncio
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 《像计算机科学家一样思考Python》——3.11 有返回值函数和无返回值函数
- 《Python Cookbook(第2版)中文版》——1.16 替换字符串中的子串
- 基于Python+Neo4j实现新冠信息挖掘系统【100010169】
- Python数据教程之在 Pandas 中向现有 DataFrame 添加新列解析xpath(解析岩石网页)
- Python实例---模拟微信网页登录(day5)
- Python实例---模拟微信网页登录(day3)
- Python实例---模拟微信网页登录(day1)
- python 访问 网页 获得源码
- python-xlrd,xlwt excel文件的读写
- 使用Python写的第一个网络爬虫程序
- python win7 appiumDesktop环境搭建
- Python 爬虫 之 爬虫的一些基本知识和基本操作(爬取视频、图片、获取网页源码等)整理
- Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)