1 #!/usr/bin/python 2 #coding:utf8 3 import re 4 import urllib 5 6 def gethtml(url): 7 page=urllib.urlopen(url) 8 html=page.read() 9 return html 10 11 def getimg(html): 12 reg=r‘<img src="(http.*?\.gif)" alt‘ 13 imgre=re.compile(reg) 14 imglist=re.findall(imgre,html) 15 ii=0 16 for imgimg in imglist: 17 urllib.urlretrieve(imgimg,‘%s.jpg‘ % ii) 18 ii+=1 19 20 aa=gethtml(‘http://www.126.com‘) 21 print getimg(aa)
原文:http://www.cnblogs.com/wjoyxt/p/3720040.html