[Tutor] Using xml.etree ElementTree
Danny Yoo
dyoo at hashcollision.org
Wed Oct 8 00:50:46 CEST 2014
>> It's working, the thing is that I don't know how to "navigate" inside the
>> XML, I read the doc but everything there regarding key-value is on
>> for-loops, I need something more direct, like:
Hi Juan,
I think you're looking for:
http://effbot.org/zone/element.htm#searching-for-subelements
where you should be able to do something like:
sml._xml.findtext('steamID64')
to get the text "76561198084537782".
Let's check:
###################################################################
>>> import xml.etree.ElementTree
>>> import urllib
>>> f = urllib.urlopen("http://steamcommunity.com/profiles/76561198084537782?xml=1")
>>> tree = xml.etree.ElementTree.ElementTree(file=f)
>>> tree.findtext('steamID64')
'76561198084537782'
###################################################################
Yup, this looks relatively straightforward. Let us know if you hit any snags.
More information about the Tutor
mailing list