如何解析XML Python中的谷歌应用程序引擎 [英] How to parse xml in Python on Google App Engine
本文介绍了如何解析XML Python中的谷歌应用程序引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有关此下面的XML ,我怎么获取XML,然后将其解析到走不出的值<年龄>
For this following xml, how do I fetch the xml and then parse it to get out the value for <age>
?
<boardgames>
<boardgame objectid="13">
<yearpublished>1995</yearpublished>
<minplayers>3</minplayers>
<maxplayers>4</maxplayers>
<playingtime>90</playingtime>
<age>10</age>
<name sortindex="1">Catan</name>
...
我目前正试图
result = urlfetch.fetch(url=game_url)
xml = ElementTree.fromstring(result.content)
但我不知道我是在正确的道路上。当我尝试解析我得到的错误(我想因为XML不是有效的XML)。
But I'm not sure I'm on the right path. When I try to parse I get errors (I think because the xml is not valid xml).
推荐答案
对我来说,以下工作:
import urllib2
from xml.etree import ElementTree
result = urllib2.urlopen('http://boardgamegeek.com/xmlapi/boardgame/13').read()
xml = ElementTree.fromstring(result)
print xml.findtext(".//age")
这篇关于如何解析XML Python中的谷歌应用程序引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文