如何解决Python lxml为西里尔字符提供实体
我正在尝试打印包含西里尔字符的字符串。
代码:
from lxml import etree
root = etree.fromstring('<root><child value="тест"/></root>')
child = root.find("child")
print(etree.tostring(child,encoding="unicode"))
...将打印:
<child value="тест"/>
这是我所期望的:
<child value="тест"/>
我该如何实现?
解决方法
尝试将Ecs
作为method="html"
的参数:
.tostring()
打印:
from lxml import etree
root = etree.fromstring('<root><child value="тест"/></root>')
child = root.find("child")
print(etree.tostring(child,method="html",encoding="unicode"))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。