python下载图片并保存本地
正则图片链接并下载
示例1
import requests
import re
url = \'http://www.nipic.com/photo/jingguan/ziran/index.html\'
response = requests.get(url).text
# print(response)
img = re.compile(\'data-src="(.*?).jpg"\')
imgs = re.findall(img,response)
i = 1
for imgurl in imgs:
i +=1
image= requests.get(imgurl).content
print(str(i)+ \'.jpg 正在保存...\')
with open(\'./img/\' + str(i)+\'.jpg\', \'wb\')as fp:
fp.write(image)
版权声明:本文为gqv2009原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。