The python2 equivalent of html.entities is htmllib.entitydefs (

On 13 May 2018 at 13:15, Thomas Levine <> wrote:
Peng Yu writes:
> I just realize that tostring() makes changes to symbols like =C2=B0. If I
> just to strip the outermost tag, without changing anything to the
> internal text. How to do it? Thanks.
> from lxml import etree
> tree =3D etree.XML('<foo>25/15=C2=B0C <bar>abc</bar></foo>')
> print etree.tostring(tree)
> The output of the above code is the following.
> <foo>25/15&#176;C <bar>abc</bar></foo>

Check the lxml documentation for a way to run tostring without XML/HTML
entities. Alternatively, replace them afterwards; I don't think it's in
Python 2, but the module html.entities may be helpful.
Mailing list for the lxml Python XML toolkit -