我在 Python 中的 unicode-string 变量中有一些 XML,如下所示:
I have some XML in a unicode-string variable in Python as follows:
<?xml version='1.0' encoding='UTF-8'?>
<results preview='0'>
<meta>
<fieldOrder>
<field>count</field>
</fieldOrder>
</meta>
<result offset='0'>
<field k='count'>
<value><text>6</text></value>
</field>
</result>
</results>
如何使用Python提取<value><text>6</text></value>
中的6
?
How do I extract the 6
in <value><text>6</text></value>
using Python?
BeautifulSoup<据我所知,/a> 是解析 XML 的最简单方法...
BeautifulSoup is the most simple way to parse XML as far as I know...
并假设您已经阅读了介绍,那么只需简单地使用:
And assume that you have read the introduction, then just simply use:
soup = BeautifulSoup('your_XML_string')
print soup.find('text').string
这篇关于如何在 Python 中获取 XML 标记值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!