-
这是个简单的爬虫程序,因为刚学Python所以记录一下
import urllib.request import re; def getHtml(url): page = urllib.request.urlopen(url); html = page.read(); return html; url="http://tieba.baidu.com/p/2460150866"; html = getHtml(url); def getImg(html): reg=r'src="(.+?\.jpg)" pic_ext'; imgre = re.compile(reg); html = html.decode('utf-8'); imglist = re.findall(imgre,html); x=0; for imgurl in imglist: urllib.request.urlretrieve(imgurl,'%s.jpg'%x); x+=1; return imglist; print(getImg(html));
网友评论