Skip to content

Instantly share code, notes, and snippets.

@otienog1
Forked from andreif/rss to json.py
Created August 27, 2018 06:46
Show Gist options
  • Save otienog1/29192e70ff71d98e3cbd8958f5c065f7 to your computer and use it in GitHub Desktop.
Save otienog1/29192e70ff71d98e3cbd8958f5c065f7 to your computer and use it in GitHub Desktop.
from collections import OrderedDict
import json
from urllib.request import urlopen
import xml.etree.ElementTree as ET
xml = urlopen(url=url).read()
items = []
for item in ET.fromstring(xml).findall('channel')[0].findall('item'):
items.append(OrderedDict((i.tag, i.text) for i in item))
print(json.dumps(items, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment