爬虫入门:爬取百度贴吧图片
2017-07-28 本文已影响0人
捉虫__羊羊
#coding = utf-8
importre
importurllib
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImg(html):
reg =r'src="(.+?\.jpg)" pic_ext'
#reg = r'src="(.+?\.jpg)" alt'
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
x=1
for imgurl in imglist:
urllib.urlretrieve(imgurl,'C:\\img\\%s.jpg'% x)
x+=1
return x
html = getHtml("https://tieba.baidu.com/p/2460150866")
print getImg(html)
执行结果一共69张图片: