Python很简洁,也很强大,作为兴趣,值得一学!
下面这个程序实现的是从一个网站上下载图片,根据自己需要可以进行修改
1 import re 2 import urllib 3 4 def gethtml(url): 5 page = urllib.urlopen(url) 6 html = page.read() 7 return html 8 9 def getimg(html): 10 reg = r'src="(.*?.jpg)"' 11 imgre = re.compile(reg) 12 imglist = re.findall(imgre, html) 13 x = 1 14 for imgurl in imglist: 15 urllib.urlretrieve(imgurl, '%s.jpg' % x) 16 x+=1 17 18 target = raw_input("Input one url:") 19 html = gethtml(target) 20 print "please wating, pictrues are downloading....." 21 getimg(html)