python爬取某个网页的图片-如百度贴吧
作者:vpoet
mail:vpoet_sir@163.com
注:随意copy,不用告诉我
#coding:utf-8
import urllib
import urllib2
import re if __name__ =="__main__":
rex=r'src="(http://imgsrc.baidu.com/forum/w%3D580.*?\.jpg)"';
Response=urllib2.urlopen("http://tieba.baidu.com/p/3842835603?fr=frs");
Html=Response.read();
lists = re.findall(rex, Html);
x=0;
for picurl in lists:
urllib.urlretrieve(picurl,'C:\Users\Administrator\Desktop\pic\%s.jpg' % x);
x=x+1;
print picurl; print 'DownLoadPicOver'
# 图片存储路径:C:\Users\Administrator\Desktop\pic
#测试爬取网址:http://tieba.baidu.com/p/3842835603?fr=frs
运行截图:
因为图片是一张张下载,可能会有点慢,等后面用了多线程,那下载飕飕的