All pastes #742187 Raw Edit

Mine

public text v1 · immutable
·published 2007-10-19 09:23 UTC
rendered paste body
#Parsers
get_url = re.compile("<link href=\"(?P<url>.*?)\"")

# Get url entered by user from form
form = cgi.FieldStorage()
url = form["url"].value

# Open url and read the feed
formdata = urllib2.urlopen(url)
blog = minidom.parse(formdata)
formdata.close

rootNode = blog.documentElement
#print rootNode.toxml()
for node in rootNode.childNodes:
    if (node.nodeName == "title"):
        for title_node in node.childNodes:
            if (title_node.nodeType == node.TEXT_NODE):
                print "  <h2 id=\"feed-title\">", title_node.nodeValue, "</h2>"
                print "  <hr class=\"seperator\" />"
    if (node.nodeName == "entry"):
        for entry_node in node.childNodes:
            if (entry_node.nodeName == "title"):
                for name_node in entry_node.childNodes:
                    if (name_node.nodeType == node.TEXT_NODE):
                        entry_title = name_node.nodeValue
            elif (entry_node.nodeName == "link"):
                match = get_url.search(entry_node.toxml())
                print "  <a href=\"", match.groupdict()['url'], "\">", entry_title, "</a> <br />"
            elif (entry_node.nodeName == "author"):
                for author_node in entry_node.childNodes:
                    if (author_node.nodeName == "name"):
                        for authname_node in author_node.childNodes:
                            if (authname_node.nodeType == node.TEXT_NODE):
                                print "  <p class=\"author\"> Author:", authname_node.nodeValue, "</p> <br />"
            elif (entry_node.nodeName == "content"):
                #get content
                content = "blah"
            elif not len(content)
                if (entry_node.nodeName == "summary"):
                    pass
                #get summary (shouldn't do so here, cuz of "blah")