Skip to content

Commit bd03751

Browse files
committed
Create xmltest.py
1 parent fdffd7e commit bd03751

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

xmltest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import urllib.request as ur
2+
import xml.etree.ElementTree as et
3+
4+
url = input('Enter location: ')
5+
# 'http://python-data.dr-chuck.net/comments_42.xml'
6+
7+
total_number = 0
8+
sum = 0
9+
10+
print('Retrieving', url)
11+
xml = ur.urlopen(url).read()
12+
print('Retrieved', len(xml), 'characters')
13+
14+
tree = et.fromstring(xml)
15+
counts = tree.findall('.//count')
16+
for count in counts:
17+
sum += int(count.text)
18+
total_number += 1
19+
20+
print('Count:', total_number)
21+
print('Sum:', sum)

0 commit comments

Comments
 (0)