【问题标题】:how to find an xml tag with special character in Python BeautifulSoup如何在 Python BeautifulSoup 中找到带有特殊字符的 xml 标签
【发布时间】:2014-10-29 09:38:37
【问题描述】:

我正在使用 Python BeautifulSoup 版本 3。 我的 xml 看起来像这样(它来自 docx 格式):-

<w:r w:rsidRPr="00541D75">
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
<w:b/>
<w:color w:val="1F497D" w:themeColor="text2"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>Mandatory / Optional</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>

我想从标签'w:t'中提取内容,所以我就是这样做的:-

print soup.findAll('w:t')

这是我收到的错误消息:-

print soup.findAll('w:t')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 43: ordinal not in range(128)

【问题讨论】:

    标签: python xml beautifulsoup


    【解决方案1】:

    美丽的对象必须定义如下:

    BeautifulSoup(markup, "lxml-xml") 
    

    BeautifulSoup(markup, "xml")
    

    doc specified

    【讨论】:

      猜你喜欢
      • 2012-04-28
      • 1970-01-01
      • 2023-03-27
      • 2011-05-16
      • 2022-01-07
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 2016-01-10
      相关资源
      最近更新 更多