python download image

如何优雅的下载图片:

1.最原始野性:

import requests

img_url = "www.tupian/xxxxx.png"

img_read = requests.get(img_src).content

with open('img_file.jpg','wb') as f:
    
    f.write(img_read)

2.含蓄

import urllib.request

img_url = "www.tupian/xxxxx.png"

urllib.request.urlretrieve(img_url ,"img_file.png")

3.优雅

import wget

img_url = "www.tupian/xxxxx.png"

wget.download(img_url ,"img_file.jpg")

4.逼格

import requests

from PIL import Image

from io import BytesIO

img_url = "www.tupian/xxxxx.png"

response = requests.get(img_url)

image = Image.open(BytesIO(response.content))

image.save("img_file.jpg")

猜你喜欢

转载自blog.csdn.net/chen13017535518/article/details/81809289
今日推荐