有什么办法可以将空白的空白分配为& nbsp;在LXML或其他Python XML lib中?

发布于 2025-01-28 02:14:05 字数 329 浏览 2 评论 0原文

我的代码是:

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

有什么方法可以在LXML或其他Python XML库中输出?

<div>&nbsp;</div>

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> </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽你眉间 2025-02-04 02:14:05

我通过将空白替换为'\ xa0'解决了这个问题(160是&amp; nbsp; ascii代码)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文