We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ddb1fed commit f1159bdCopy full SHA for f1159bd
Using Python to Access Web Data/W5_Ass_Extracting_Data_from_XML
@@ -0,0 +1,28 @@
1
+import xml.etree.ElementTree as ET
2
+import urllib.request, urllib.parse, urllib.error
3
+import ssl
4
+
5
+ctx = ssl.create_default_context()
6
+ctx.check_hostname = False
7
+ctx.verify_mode = ssl.CERT_NONE
8
9
+#url = "http://py4e-data.dr-chuck.net/comments_853294.xml"
10
+url = input('Enter location: ')
11
+print("Retrieving",url)
12
+xml = urllib.request.urlopen(url).read()
13
14
+clen=len(xml)
15
+print("Retrieved", clen ,"characters")
16
17
+sum = 0
18
+temp = 0
19
20
+tree = ET.fromstring(xml)
21
+counts = tree.findall('.//count')
22
+for count in counts:
23
+ temp = temp + 1
24
+ #print(count.text)
25
+ sum = sum + int(count.text)
26
27
+print("Count:",temp)
28
+print("Sum:",sum)
0 commit comments