1 import urllib.request 2 import re 3 4 def getHtml(url): 5 html = urllib.request.urlopen(url).read() 6 return html 7 8 def getImg(html): 9 reg = r'src="(.+?\.jpg)" pic_ext' 10 imgre = re.compile(reg) 11 html = html.decode('utf-8') 12 imglist = re.findall(imgre,html) 13 14 x = 0 15 16 for imgurl in imglist: 17 urllib.request.urlretrieve(imgurl,'%s.jpg' %x) 18 x += 1 19 return imglist 20 21 html = getHtml("http://tieba.baidu.com/p/2460150866") 22 print(getImg(html))
浙公网安备 33010602011771号