#! /usr/bin/env python import urllib2 from xml.dom import minidom, Node """ Get the XML """ url_info = urllib2.urlopen('http://rss.slashdot.org/Slashdot/slashdot') if (url_info): """ We have the RSS XML lets try to parse it up """ xmldoc = minidom.parse(url_info) if (xmldoc): """We have the Doc, get the root node""" rootNode = xmldoc.documentElement """ Iterate the child nodes """ for node in rootNode.childNodes: """ We only care about "item" entries""" if (node.nodeName == "item"): """ Now iterate through all of the 's children """ for item_node in node.childNodes: if (item_node.nodeName == "title"): """ Loop through the title Text nodes to get the actual title""" title = "" for text_node in item_node.childNodes: if (text_node.nodeType == node.TEXT_NODE): title += text_node.nodeValue """ Now print the title if we have one """ if (len(title)>0): print title if (item_node.nodeName == "description"): """ Loop through the description Text nodes to get the actual description""" description = "" for text_node in item_node.childNodes: if (text_node.nodeType == node.TEXT_NODE): description += text_node.nodeValue """ Now print the title if we have one. Add a blank with \n so that it looks better """ if (len(description)>0): print description + "\n" else: print "Error getting XML document!" else: print "Error! Getting URL"