Skip to content

Instantly share code, notes, and snippets.

@jameslyons
Last active October 25, 2016 15:04
Show Gist options
  • Save jameslyons/8468367 to your computer and use it in GitHub Desktop.
Save jameslyons/8468367 to your computer and use it in GitHub Desktop.
import urllib
from xml.etree.ElementTree import parse
URL = '''http://jameslyons0.blogspot.com.au/feeds/posts/default?max-results=9999'''
xml = parse(urllib.urlopen(URL)).getroot()
info = {}
for post in xml.getchildren():
if post.tag=='{http://www.w3.org/2005/Atom}entry':
headers,title,link=[],None,None
for entry in post.getchildren():
if entry.tag=='{http://www.w3.org/2005/Atom}category':
headers.append(entry.attrib['term'])
if entry.tag=='{http://www.w3.org/2005/Atom}title':
title = entry.text
if entry.tag=='{http://www.w3.org/2005/Atom}link':
link = entry.attrib['href']
for h in headers:
if h not in info: info[h] = [(title,link)]
else: info[h].append((title,link))
for label in info.keys():
print "<h2>",label,"</h2>"
for title,link in info[label]:
print '<a href="',link,'">',title,'</a><br />'
print '<br />'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment