python网络爬虫(1)--抓取图片(2)
来源:互联网 发布:中国吸血鬼网络剧 编辑:程序博客网 时间:2024/05/18 03:57
上一篇用来HTML解析器来解析网页源代码,这次用正则表达式来解析
同上一篇略同,代码如下:
本次抓取Google图片
# getimage.pyimport urllib.requestimport refrom urllib.error import HTTPError, URLErrorurl = 'https://www.google.com.hk/search?safe=strict&hl=zh-CN&biw=1366&bih=638&s' \ 'ite=imghp&tbm=isch&sa=1&btnG=Google+%E6%90%9C%E7%B4%A2&q=%E8%87%AA%E7%84%B6'# pretend as a browserheaders = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1;\ WOW64; rv:23.0) Gecko/20100101 Firefox/23.0 '}url2 = urllib.request.Request(url, headers=headers)# get the source code form urlfb = urllib.request.urlopen(url2)souCode = fb.read().decode('utf-8')# get what you want form souCodedownLists = re.findall('http\S+.jpg', souCode)# download form urlLists to your catalogi = 0for lists in downLists: print(lists) try: urllib.request.urlretrieve(lists, 'C:\\image\\nature\\nature%s.png' % i) except HTTPError: continue except URLError: continue except UnicodeEncodeError: continue i += 1
注意:需要异常处理,以为有些图片是打不开的,或网页编程者出错的。
0 0
- python网络爬虫(1)--抓取图片
- python网络爬虫(1)--抓取图片(2)
- Python网络爬虫(4)煎蛋网妹子图片抓取
- python网络爬虫抓取图片
- python 网络爬虫抓取图片
- python网络爬虫抓取图片
- python网络爬虫抓取图片
- python网络爬虫抓取图片
- python爬虫(一)抓取 色影无忌图片
- python爬虫(抓取百度图片)
- python网络爬虫(五):并发抓取
- python网络爬虫,抓取网页图片
- Python爬虫之抓取网络图片
- python爬虫实战(1)抓取网页图片自动保存
- Python网络爬虫(6)糗事百科图片抓取按主题名保存
- python爬虫抓取图片
- Python爬虫---------------<妹子图>图片抓取(1)
- Python网络爬虫(Get、Post抓取方式)
- PAT-A-1032. Sharing (25)
- Tensorflow自我训练进阶(代码+注解)【2】第一个神经网络--简单感知器处理MNIST
- Linux下FFMPEG 简单的Demo开发
- 计算机系统知识汇总
- 无向图的割顶和桥
- python网络爬虫(1)--抓取图片(2)
- IDEA下搭建maven实例项目
- redis主从复制
- Python购物车系统模拟1
- Meisell-Lehmer算法(求1...n范围内的素数个数)
- 命名管道的通信方式
- Java编程思想-16数组
- Android中内存泄漏的原因及消除内存泄漏的方法
- ViewPager实现广告条自动滑动