Skip to content

Commit f1159bd

Browse files
authored
Extracting_Data_from_XML
1 parent ddb1fed commit f1159bd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)