Python 爬虫网页抓图保存
来源:互联网 发布:seo招聘北京 编辑:程序博客网 时间:2024/05/01 03:18
网站选择桌面壁纸网站的汽车主题:
下面的两个print在调试时打开
#print tag#print attrs
#!/usr/bin/env pythonimport reimport urllib2import HTMLParserbase = "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 attrsif(self.Index):if not cmp(tag,'a'):if(len(attrs) == 4):if(attrs[0] ==('class','pic')):#print tag#print attrsnew = base+attrs[1][1]print 'found a link:',newglobal starstar = newget_url(new)else:if not cmp(tag,'img'):if(attrs[0] == ('id','bigImg')):#print tag#print attrsImage_url = attrs[1][1]print 'found a picture:',Image_urldownload(Image_url)if not cmp(tag,'a'):if (len(attrs) == 4):if (attrs[1] == ('class','next')):#print tag#print attrsnext = base + attrs[2][1]print 'found a link:',nextif (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)
仅仅就是抓桌面壁纸网站上的优美的壁纸 。。。
1 0
- Python 爬虫网页抓图保存
- python爬虫抓网页的总结
- python爬虫抓网页的总结
- python 爬虫入门1 网页图片保存
- Python爬虫之路——简单的网页抓图
- Python爬虫之路——简单网页抓图升级版(增加多线程支持)
- Python爬虫之路——简单网页抓图升级版(增加多线程支持)
- Python爬虫之路——简单的网页抓图
- python爬虫第一弹之抓图
- python 爬虫抓站
- Python 爬虫抓站
- python 爬虫抓站
- python 爬虫抓小说
- Python爬虫,抓图片
- python 网页爬虫+保存图片+多线程+网络代理
- python 网页爬虫+保存图片+多线程+网络代理
- python爬虫实战(1)抓取网页图片自动保存
- Python抓网页内容
- ios8来了,屏幕更大,准备好使用 iOS Auto Layout了吗?
- EasyConnect
- 关于IOS8的Autolayout特性的理解以及使用
- Java的内部类(Inner Class)和嵌套类(Nested Class)的区别
- poj1149 PIGS DINIC
- Python 爬虫网页抓图保存
- POJ 2373 (Dividing the Path)单调队列优化DP
- SSH框架搭建
- unity3d学习之镜头耀斑
- 今天学了【链地址法处理冲突构造哈希表】,帮别人写了个程序。
- 在dos命令行里面INSERT中文总是报错解决办法
- 我的大学,追忆高三(永不能忘的332)
- unity3d学习之预设体
- 【软件工程】软件开发的领路者——过程模型