Home > OS >  Is there any way to outout blank as   in lxml or other python xml lib?
Is there any way to outout blank as   in lxml or other python xml lib?

Time:05-17

my code is:

>>> from lxml.html import tostring, HtmlElement
>>> a = HtmlElement()
>>> a.tag = "div"
>>> a.text = " "
>>> tostring(a)
b'<div> </div>'

Is there any way to output like in lxml or other python xml library?

<div>&nbsp;</div>

CodePudding user response:

I solved this problem by replace blank to '\xa0' (160 is &nbsp; ascii code)

  • Related