python用requests.get批量下载网络远程图片的代码
python用requests.get批量下载网络远程图片的代码
# coding=utf-8
"""# 导入re模块,直接调用来实现正则匹配
import re
import requests
# 定义变量url 获取要下载图片的地址
url = "https://www.zzzyk.com"
# 使用get()来获取url
r = requests.get(url)
imglist = re.findall('src="(.+?\.jpg)" pic_ext',r.text)
# 定义变量x并初始化用来计数图片的张数
x = 0
# 遍历
for imgurl in imglist:
# 获取获得的从imglist中遍历得到的imgurl
imgres = requests.get(imgurl)
with open("yizuotu.net\{}.jpg".format(x), "wb") as f:
f.write(imgres.content)
x +=1
print("第", x ,"张")
print("下载完毕")