正则图片链接并下载

示例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 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/gqv2009/p/13054289.html