Skip to content

Instantly share code, notes, and snippets.

@rmgimenez
Created July 5, 2016 18:27
Show Gist options
  • Save rmgimenez/a12f7bca92bb801c777d83740a3e1c4a to your computer and use it in GitHub Desktop.
Save rmgimenez/a12f7bca92bb801c777d83740a3e1c4a to your computer and use it in GitHub Desktop.
Ler xml reddit imgur
from urllib.request import urlopen
import xml.etree.ElementTree as ET
link_xml = 'http://imgur.com/r/cosplay/top/day.xml';
arq_xml = urlopen(link_xml)
xml = ET.parse(arq_xml)
items = []
for item_xml in xml.findall('item'):
lista = {
'id': item_xml.find('id').text,
'hash': item_xml.find('hash').text,
'author': item_xml.find('author').text,
'title': item_xml.find('title').text,
'score': item_xml.find('score').text,
'size': item_xml.find('size').text,
'views': item_xml.find('views').text,
'is_album': item_xml.find('is_album').text,
'mimetype': item_xml.find('mimetype').text,
'ext': item_xml.find('ext').text
}
items.append(lista)
for item in items:
print('====')
for k, i in item.items():
print(k, i)
print('====')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment