From bd0375131d83c5d93f8352c9f1d5662f0053208e Mon Sep 17 00:00:00 2001 From: Rohan Kumara <31560310+rohankumara@users.noreply.github.com> Date: Fri, 25 Sep 2020 16:40:38 +0530 Subject: [PATCH] Create xmltest.py --- xmltest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 xmltest.py diff --git a/xmltest.py b/xmltest.py new file mode 100644 index 0000000..ac03be1 --- /dev/null +++ b/xmltest.py @@ -0,0 +1,21 @@ +import urllib.request as ur +import xml.etree.ElementTree as et + +url = input('Enter location: ') +# 'http://python-data.dr-chuck.net/comments_42.xml' + +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)