How to parse data-uri in python?

后端 未结 6 1237
逝去的感伤
逝去的感伤 2020-12-04 01:59

HTML image elements have this simplified format:


That something can be data-uri, for example:



        
6条回答
  •  误落风尘
    2020-12-04 02:38

    Split the data URI on the comma to get the base64 encoded data without the header. Call base64.b64decode to decode that to bytes. Last, write the bytes to a file.

    from base64 import b64decode
    
    data_uri = "data:image/png;base64,iVBORw0KGg..."
    
    # Python 2 and 

提交回复
热议问题