糖逗 发表于 2022-6-12 14:47:01

python将url图片保存为jpg到本地

from io import BytesIO
import 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]
查看完整版本: python将url图片保存为jpg到本地