BeautifulSoup可以在Windows上用lxml解析器找到xml节点,但在Linux上找不到

2024-05-28 19:44:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个xml文件,内容如下

content ="""<?xml version="1.0" ?>
<passage>
  <title>Aggrecan Turnover</title>
  <author>Winsz-Szczotka K,Kuźnik-Trocha K,Komosińska-Vassev K,Jura-Półtorak A,Olczyk K</author>
  <source>Disease markers</source>
  <description>
   xxxxxxx
  </description>
  <filename>26924871.xml</filename>
  <passage_url>http://www.ncbi.nlm.nih.gov/pubmed/26924871</passage_url>
  <received_date>2016-03-02</received_date>
  <parameter_date>2016-02-29</parameter_date>
</passage>"""

from bs4 import BeautifulSoup
soup = BeautifulSoup(content, "xml")
soup.find("author")

结果:

在Windows上:

<author>Winsz-Szczotka K,Kuźnik-Trocha K,Komosińska-Vassev K,Jura-Półtorak A,Olczyk K</author>

在Linux上

什么也找不到, 当我将<author>节点更改为<author>Winsz-Szczotka</author>时,它可以在Windows和Linux中找到该节点,那么这是怎么回事呢?你知道吗

另外,当我在Linux上把解析器改为html.parser时,它运行得很好,我很困惑,内容是xml格式的,为什么要使用html.parse文件工作顺利吗? 任何人都可以告诉我一些事情,谢谢。你知道吗


Tags: 文件内容datetitlelinuxxmlcontentauthor

热门问题