项目场景:
selenium 获取src为“data:image/jpg;base64,…”
问题描述
"data:image/jpg;base64,"后面的字符为base64编码的bytes,因此直接解码后保存为图片就会,不需要使用requests去get。
import base64
# 取"data:image/jpg;base64,"后面的数据
content = src[22:]
# str转bytes
content_to_bytes = bytes(src, 'utf-8')
# 解码并保存为图片
with open(f'content.jpg', 'wb') as file:
file.write(base64.decodebytes(content_to_bytes))