File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Week 5 Web Services and XML/Assignments Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
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 )
22
+
23
+
24
+ # ======= Outputs ======
25
+ # Enter location: http://python-data.dr-chuck.net/comments_42.xml
26
+ # Retrieving http://python-data.dr-chuck.net/comments_42.xml
27
+ # Retrieved 4204 characters
28
+ # Count: 50
29
+ # Sum: 2482
You can’t perform that action at this time.
0 commit comments