Parse XML (musicbrainz) In Python



I am trying to import urls like this one (http://ift.tt/1H6tNwB) into python and extract the value of the "gender".



import urllib2
import codecs
import sys
import os
from xml.dom import minidom
import xml.etree.cElementTree as ET

#urlbob = urllib2.urlopen('http://ift.tt/1H6tNwB')
url = 'dylan.xml'

#attempt 1 - using minidom
xmldoc = minidom.parse(url)
itemlist = xmldoc.getElementsByTagName('artist')

#attempt 2 - using ET
tree = ET.parse('dylan.xml')
root = tree.getroot()

for child in root:
print child.tag, child.attrib


I can't seem to get at gender either via the mini-dom stuff or the etree stuff. In its current form, the script returns



{http://ift.tt/1q9AHMn {'type': 'Person', 'id': '72c536dc-7137-4477-a521-567eeb840fa8'}

No comments:

Post a Comment