【发布时间】:2023-03-25 12:05:01
【问题描述】:
我正在使用 BeautifulSoup 来解析 XML:
In [64]: b = bs4.BeautifulSoup('<xml><t xml:space="preserve"> </t><t xml:space="preserve"> A </t></xml>', 'xml')
In [65]: b.find_all('t')
Out[65]: [<t xml:space="preserve"> </t>, <t xml:space="preserve"> A </t>]
因此,尽管有xml:space="preserve" 属性,但第一个t 标记中的5 个空格被折叠成1 个。
有没有办法让 BeautifulSoup 尊重 xml:space="preserve" 而不会折叠空格?
【问题讨论】:
标签: python xml beautifulsoup