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)
原文地址:https://www.cnblogs.com/gqv2009/p/13054289.html