爬虫
爬取昵图网图片并保存
# -*- coding: utf-8 -*- import re import urllib def getHtml(url): page = urllib.urlopen(url) html = page.read() return html def getImg(html,p): reg = r'<img src="(.+\.jpg)"' imgre = re.compile(reg) imglist = re.findall(imgre,html) x = 0; for imgurl in imglist: y = str(p) + '-'+ str(x); urllib.urlretrieve(imgurl,'./images/%s.jpg' % y) x+=1 for i in range(19,60 +1): url = "http://www.nipic.com/zhuanti/817811_"+ str(i) +".html" print url html = getHtml(url) print getImg(html,p=i)