Python爬虫获取知乎图片
2016-12-09 22:15
375 查看
前段时间想抓点知乎问题中的图片,了解了下爬虫,发现还是Python的简单方便,于是做了点尝试.
把getHtml中的URL换成自己想获取的知乎问题就可以用了,默认是保存在xxx.py所在的文件夹中.
#coding=utf-8 import urllib import re def getHtml(url): page = urllib.urlopen(url) html = page.read() return html def getImg(html): # reg = r'<noscript><img src="(.+?\.jpg)"' reg = r'data-actualsrc="(.+?\.jpg)"' imgre = re.compile(reg) imglist = re.findall(imgre,html) x = 0 for imgurl in imglist: urllib.urlretrieve(imgurl,'%s.jpg' % x) x+=1 html = getHtml("https://www.zhihu.com/question/24278285") print getImg(html)
把getHtml中的URL换成自己想获取的知乎问题就可以用了,默认是保存在xxx.py所在的文件夹中.
相关文章推荐
- python Requests 知乎问题图片爬虫
- 【python爬虫】爬取知乎收藏夹内所有图片
- Python练手爬虫系列No.1 知乎福利收藏夹图片批量下载
- python爬虫三:获取一个网易用户的所有图片(selenium+phantomjs)
- Python爬虫之知乎图片抓取
- Python Requests爬虫——获取一个收藏夹下所有答案的图片
- Python爬虫获取图片并下载保存至本地
- Python3爬虫(5)--获取知乎用户的粉丝
- python爬虫(9)获取动态搞笑图片
- python爬虫——获取图片2
- Python3爬虫入门之贴吧图片批量获取
- python 爬虫获取网页图片
- Python 爬虫获取百度贴吧图片
- Python爬虫(5)——获取京东手机图片
- python3.X爬虫-图片获取
- 通过Python爬虫爬取知乎某个问题下的图片
- 【Python爬虫基础】抓取知乎页面所有图片
- Python简单知乎爬虫--爬取页面的图片并下载到本地
- python爬虫 分页获取图片并下载
- Python实现简单的获取图片爬虫功能示例