Learn to code and help non-profits:


Using ElementTree to find ‘count’ tag and sum them

Some small piece of code:

import urllib
import xml.etree.ElementTree as ET

sum = 0

url = raw_input('Enter location: ')
if len(url) < 1 : exit()

print 'Retrieving', url
uh = urllib.urlopen(url)
data =
print 'Retrieved',len(data),'characters'
#print data

tree = ET.fromstring(data)
results = tree.findall('.//count')

for i in range(0, len(results)):
 sum = sum + int(results[i].text)
print "Count: %i" % len(results)
print "Sum: %i" % sum