字节保存为图片

import iofrom PIL 
import Image
import requests
url_get = '[http://192.168.0.223:8787/xx(隐藏地址)](http://192.168.0.223:port/xx(隐藏地址))' #某个获取验证码接口

hearders={"tag":33}

response = requests.get (url=url_get,params=hearders)

byte_stream = io.BytesIO(response.content) #请求数据转化字节流

roiImg = Image.open(byte_stream)#Image打开二进制流Byte字节流数据

imgByteArr = io.BytesIO() # 创建一个空的Bytes对象

roiImg.save(imgByteArr, format='PNG') # PNG就是图片格式

imgByteArr = imgByteArr.getvalue() #保存的二进制流

with open("./abc.png", "wb") as f:

f.write(imgByteArr)
posted @ 2022-12-15 17:23  木子墨墨  阅读(92)  评论(0编辑  收藏  举报