[Tutor] Using xml.etree ElementTree

Juan Christian juan0christian at gmail.com
Wed Oct 8 00:03:32 CEST 2014


On Tue, Oct 7, 2014 at 4:08 PM, Juan Christian <juan0christian at gmail.com>
wrote:

> I have this XML scheme:
> http://steamcommunity.com/profiles/76561198084537782?xml=1
>
> My code:
>
> self._xml = ElementTree.fromstring(requests.get(url + '?xml=1').content)
> print(self._xml.tag) > returns > profile
>
> 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:
>
> XML.steamID64
> XML.steamID
> XML.onlineState
> XML.vacBanned
> ...
>
> Something like that, where I provide the key (<xmltag>) and get the value
> (<xmltag>value</xmltag>). Is that possible?
>


So.. I found that I can do it with 'self._xml[index].text', but that's not
a good and 'visible' way to do things. Explicit is better than implicit,
and this XML has some data that might or might not be there, so I can't
trust in the index.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141007/66924fa9/attachment.html>


More information about the Tutor mailing list