如何在Python BeautifulSoup中找到具有特殊字符的xml标记

2024-09-24 02:18:38 发布

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

我使用的是Python beautifulsoupversion3。 我的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'中提取内容,所以这就是我做过:在

^{pr2}$

这是我的错误消息得到:在

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

Tags: innew格式asciivalxmlcsdocx