Reputation: 4190
I'm using lxml and I'm trying to get the original xml string so:
>>> elem = etree.fromstring("<tag>áéíóúñü</tag>")
>>> etree.tostring(elem)
b'<tag>áéíóúñü</tag>'
The only way that I found to get the original string is doing:
>>> etree.tostring(elem, encoding = "utf-8").decode("utf-8")
'<tag>áéíóúñü</tag>'
Is there a better aproach?
Upvotes: 4
Views: 3755
Reputation: 5603
How about this:
In [31]: elem = etree.fromstring("<tag>❄</tag>")
In [32]: etree.tostring(elem, encoding=str)
Out[32]: '<tag>❄</tag>'
Upvotes: 3