关注公众号:Python爬虫数据分析挖掘,免费获取更多开源项目源码

Python 爬虫保存图片

 

最近在写爬虫但是图片保存用了很多种方法都没办法实现
最后用这种方法实现了

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)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-07-02
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
猜你喜欢
  • 2021-08-05
  • 2021-11-23
  • 2021-12-02
  • 2022-12-23
  • 2021-11-18
  • 2021-12-14
  • 2022-12-23
相关资源
相似解决方案