首页 > 解决方案 > Python 下载带有请求与请求、枕头和 BytesIO 的图像。后者的优势是什么?

问题描述

使用 Python 下载图像有两种可行的解决方案。

1.

import requests
response = requests.get(img_url)
with open('image.png', 'wb') as f:
    f.write(response.content)
import requests
from io import BytesIO
from PIL import Image    
response = requests.get(img_url)
im = Image.open(BytesIO(response.content))
im.save('image.png')

为什么要打扰第二个(我在其他人的代码中看到过)?与第一种简洁明了的方法相比,它有什么优势吗?

标签: python-3.xpython-requestspython-imaging-libraryimagedownloadbytesio

解决方案


推荐阅读