jarrod817
12/12/2015 - 3:53 AM

Coursera - Open website with XML and parse numbers and sum them.

Coursera - Open website with XML and parse numbers and sum them.

import urllib
import xml.etree.ElementTree as ET
numbers = list()
link = 'http://python-data.dr-chuck.net/comments_184196.xml'
soup = urllib.urlopen(link).read()
stuff = ET.fromstring(soup)
lst = stuff.findall('comments/comment')
for item in lst:
    value = item.find('count').text
    numbers.append(value)
numbers = ([int(i) for i in numbers])
print sum(numbers)