Processing RSS/RDF via xml.dom.minidom

Posted by Bill on Stack Overflow See other posts from Stack Overflow or by Bill
Published on 2010-03-31T07:43:09Z Indexed on 2010/04/02 8:13 UTC
Read the original article Hit count: 340

Filed under:
|

I'm trying to process a delicious rss feed via python. Here's a sample:

...
  <item rdf:about="http://weblist.me/">
    <title>WebList - The Place To Find The Best List On The Web</title>
    <dc:date>2009-12-24T17:46:14Z</dc:date>
    <link>http://weblist.me/</link>
    ...
  </item>
  <item rdf:about="http://thumboo.com/">
    <title>Thumboo! Free Website Thumbnails and PHP Script to Generate Web Screenshots</title>
    <dc:date>2006-10-24T18:11:32Z</dc:date>
    <link>http://thumboo.com/</link>
...

The relevant code is:

def getText(nodelist):
    rc = ""
    for node in nodelist:
        if node.nodeType == node.TEXT_NODE:
            rc = rc + node.data
    return rc

dom = xml.dom.minidom.parse(file)
items = dom.getElementsByTagName("item")
for i in items:
    title = i.getElementsByTagName("title")
    print getText(title)

I would think this would print out each title, but instead I get basically get blank output. I'm sure I'm doing something stupid wrong, but no idea what?

© Stack Overflow or respective owner

Related posts about python

Related posts about rss