最近在写爬虫但是图片保存用了很多种方法都没办法实现
最后用这种方法实现了
import os,base64
import requests as req
from PIL import Image
from io import BytesIO
# 图片链接
response = req.get("https://bdfile.bluemoon.com.cn/group2/M00/0A/BA/wKg_HlwzY1SAIdXDAAFyo-ZOLKQ399.jpg")
# 内存中打开图片
image = Image.open(BytesIO(response.content))
# 图片的base64编码
ls_f = base64.b64encode(BytesIO(response.content).read())
# base64编码解码
imgdata = base64.b64decode(ls_f)
# 图片文件保存
with open('图片名.jpg', 'wb') as f:
f.write(imgdata)