1 #!/usr/bin/python 2 #coding=utf-8 3 import urllib 4 import re 5 6 def gethtml(url): 7 page=urllib.urlopen(url) 8 html=page.read() 9 return html 10 11 def getjpg(html): 12 r=r'<[^>]*src="(http:[^>]+.jpg)"' 13 pat = re.compile(r) 14 urllist=re.findall(pat,html) 15 return urllist 16 17 def download(l): 18 i=1 19 for url in l: 20 print url 21 urllib.urlretrieve(url,'%s.jpg'%i) 22 i+=1 23 print 'download ok...' 24 return; 25 26 url=raw_input("please input url:") 27 html = gethtml(url) 28 l=getjpg(html) 29 #print l 30 download(l)