爬虫导出图片

#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="(https:.+?[\.jpg,\.jpeg])"'
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
print type(imglist)
print len(imglist)
x = 0
#下载并修改文件名
for imgurl in imglist:
urllib.urlretrieve(imgurl,'%s.jpg' % x)
x+=1


html = getHtml("https://tieba.baidu.com/index.html")

getImg(html)

posted on 2017-11-01 22:26  逆风飞1  阅读(115)  评论(0)    收藏  举报

导航