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