我发现有两种方法可以使用python reuqests下载图像
使用文件(https://requests.readthedocs.io/en/master/user/quickstart/#binary-response-content)中所述的PIL:
from PIL import Image
from io import BytesIO
i = Image.open(BytesIO(r.content))
使用流式响应内容:
r = requests.get(url, stream=True)
with open(image_name, 'wb') as f:
for chunk in r.iter_content():
f.write(chunk)
但是,建议wya下载哪些图像?这两种方法都有其优点,我想知道什么是最佳方法
我确实在一个函数中使用了下面几行代码来保存图像
我喜欢极简主义的方式。没有所谓的正确方法。这取决于您想要执行的任务和约束条件
相关问题 更多 >
编程相关推荐