python爬取某个网站的图片并保存到本地
#coding:utf-8 import urllib import re import sys reload(sys) sys.setdefaultencoding('gb2312') #获取整个页面的数据 def getHtml (url): page = urllib.urlopen(url) html = page.read() return html #保存图片到本地 def getImg(html): reg = r'src="(.+?.jpg)"' 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://www.666hdhd.com/?tz") print getImg(html)