Skip to content

Commit

Permalink
Create xmltest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
zpvk committed Sep 25, 2020
1 parent fdffd7e commit bd03751
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions xmltest.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit bd03751

Please sign in to comment.