我对lxml有个小问题。我正在将XML文档转换为HTML文档。 原始XML如下所示(看起来像HTML,但在XML文档中):
<p>Localization - Eiffel tower? Paris or Vegas <p>Bayes theorem p(A|B)</p></p>
当我这样做时(项目是上面的字符串)
^{pr2}$我明白了:
<div><p>Localization - Eiffel tower? Paris or Vegas </p><p>Bayes theorem p(A|B)</p></div>
我对<;div>;没有任何问题,但是“Bayes定理”段落不再嵌套在外部段落中是一个问题。在
有人知道lxml为什么要这么做,以及如何阻止它吗?谢谢。在
您使用的是lxml的HTML解析器,而不是XML解析器。试试这个:
lxml这样做是因为它不存储无效的HTML,以及HTML中的
<p>
元素can't be nested:相关问题 更多 >
编程相关推荐