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)
posted @ 2020-06-06 12:41  莫贞俊晗  阅读(2532)  评论(0编辑  收藏  举报