#coding=utf-8
import urllib
import re
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImg(html):
reg = r'src="(http.+?\.jpg)"'
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
print imglist
x = 0
for imgurl in imglist:
urllib.urlretrieve(imgurl,'%s.jpg' % x)
print imgurl
x+=1
if __name__ == '__main__':
print 'start...'
html = getHtml("https://www.zhihu.com/question/30950901")
# print html
getImg(html)
print 'The end.'
python简单爬虫(下载知乎图片示例)
最新推荐文章于 2024-07-22 17:25:13 发布