Tuesday, September 17, 2013

Reading XML in python

#!/usr/bin/env python

import xml.etree.ElementTree as ET
import httplib
import urllib2
tree = ET.parse('popularity_response.xml')
root = tree.getroot()
print root
for popularity_record in root.findall('POPULARITY_RECORD'):
 print popularity_record.find('FIELD_VALUE').text
 try : 
  response =     urllib2.urlopen(popularity_record.find('FIELD_VALUE').text)
  print response.code
 except urllib2.URLError as e :
  print e
  continue

No comments: