python将url图片保存为jpg到本地
from io import BytesIOimport requests
from PIL import Image
i = 1
for img_url in urls:
#下载图片,并保存到文件夹中
req=requests.get(img_url)
image = Image.open(BytesIO(req.content))
print(i)
filename = str(i) + '.jpg'
path = "C:\\Users\\admin\\Pictures\\img\\"
i += 1
with open(path+filename,'wb') as f:
f.write(req.content)
页:
[1]