Skip to content

Instantly share code, notes, and snippets.

@troyscott
Created January 29, 2012 09:26
Show Gist options
  • Save troyscott/1698010 to your computer and use it in GitHub Desktop.
Save troyscott/1698010 to your computer and use it in GitHub Desktop.
Convert a rss feed to a python dictionary
import xml.etree import ElementTree
# For example create doc using ElmentTree
# ElementTree.fromstring(xml)
def rss_to__dict(doc):
# Create a Dictionary to store the data
# from the rss feed (xml)
rss = {"rss":[]}
for feed in doc.findall("channel/item"):
# Create a Dictionary for the current item
item = {}
for items in feed:
item[items.tag] = items.text
rss["rss"].append(item)
return rss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment