本文介紹了如何在 Python 中獲取 XML 標記值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在 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 標記值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!