如何在python中解析data-uri? [英] How to parse data-uri in python?
本文介绍了如何在python中解析data-uri?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML图片元素此简化格式:
HTML image elements have this simplified format:
<img src='something'>
某事可以 data-uri
,例如:
That something can be data-uri
, for example:
data:image/png;base64,iVBORw0KGg...
是否有使用python解析这个的标准方法,以便我得到 content_type
和base64数据,或者我应该为此创建自己的解析器吗?
Is there a standard way of parsing this with python, so that I get content_type
and base64 data separated, or should I create my own parser for this?
推荐答案
你可以试试这个:
from base64 import decodestring
arr = "data:image/png;base64,iVBORw0KGg..."
fh = open("imageToSave.png", "wb")
fh.write(str(arr.split(",")[1].decode('base64')))
fh.close()
这篇关于如何在python中解析data-uri?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文