Assignment 5 Extracting Data From XML
Assignment 5 Extracting Data From XML
We provide two files for this assignment. One is a sample file where we give you
the sum for your testing and the other is the actual data you need to process for
the assignment.
import urllib.request as ur
import xml.etree.ElementTree as et
total_number = 0
sum = 0
print('Retrieving', url)
xml = ur.urlopen(url).read()
print('Retrieved', len(xml), 'characters')
tree = et.fromstring(xml)
counts = tree.findall('.//count')
for count in counts:
sum += int(count.text)
total_number += 1
print('Count:', total_number)
print('Sum:', sum)