【发布时间】:2012-03-25 23:26:12
【问题描述】:
我正在使用 Beautiful Soup 解析一个 xml 文件,但在解析空元素时发现了不一致的行为。即
from BeautifulSoup import BeautifulSoup
s1 = "<c><a /><b /></c>"
s2 = "<c><a></a><b></b></c>"
soup1 = BeautifulSoup(s1)
soup2 = BeautifulSoup(s2)
print soup1
# <c><a><b></b></a></c>
print soup2
# <c><a></a><b></b></c>
请注意,b 标记在第一种情况下位于 a 标记内,而在第二种情况下则不在。我认为 XML 规范意味着 s1 和 s2 是等价的?
有什么想法可以解决这个问题吗?
【问题讨论】:
标签: python xml beautifulsoup