Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: Can iterate sub elements using elementTree
    primarykey
    data
    text
    <p>I have the following code to parse an XML but it just won't let me iterate through the children:</p> <pre><code>import urllib, urllib2, re, time, os import xml.etree.ElementTree as ET def wgetUrl(target): try: req = urllib2.Request(target) req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3 Gecko/2008092417 Firefox/3.0.3') response = urllib2.urlopen(req) outtxt = response.read() response.close() except: return '' return outtxt newUrl = 'http://feeds.rasset.ie/rteavgen/player/playlist?showId=10056467' data = wgetUrl(newUrl) tree = ET.fromstring(data) #tree = ET.parse(data) for elem in tree.iter('entry'): print elem.tag, elem.attrib </code></pre> <p>Now, If I remove 'entry' from the iter I get an output like this (Why the URL??):</p> <pre><code>{http://www.w3.org/2005/Atom}entry {} {http://www.w3.org/2005/Atom}id {} {http://www.w3.org/2005/Atom}published {} {http://www.w3.org/2005/Atom}updated {} {http://www.w3.org/2005/Atom}title {'type': 'text'} </code></pre> <p>But, If I put the iter statement like this it still does not find the children to entry:</p> <pre><code>for elem in tree.iter('{http://www.w3.org/2005/Atom}entry'): print elem.tag, elem.attrib </code></pre> <p>I still only get the entry element on it's own, not the children:</p> <pre><code>{http://www.w3.org/2005/Atom}entry {} </code></pre> <p>Any idea what I am doing wrong? </p> <p>I have searched everywhere but can't figure this out... I am new to all this so sorry if it is something stupid.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload