etree.fromstring 接受无效的 xml

问题描述 投票:0回答:1

我想测试 python 中的服务器是否发送了无效的 xml..

代码是

content_element = etree.fromstring(content)

xml 类似:

<data = ""></data>

所以由于“”它是无效的

python xml elementtree
1个回答
0
投票

我认为你不能强迫 xml.etree 接受错误的 xml,但你可以使用

beautifulsoup

读取错误的 xml
from bs4 import BeautifulSoup
soup = BeautifulSoup(content, 'lxml')
© www.soinside.com 2019 - 2024. All rights reserved.