#coding=utf-8 import re import urllib
def getHtml(url): #获取url对应得源码 page = urllib.urlopen(url) html = page.read() return html def getImg(html): #获取 reg = r‘src="(.+?\.jpg)" pic_ext‘ 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("http://tieba.baidu.com/p/2460150866") #将这个页面的图片都爬下来 #print getImg(html)
参考:http://www.cnblogs.com/fnng/p/3576154.html