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 f1159bd commit aee1a05Copy full SHA for aee1a05
Using Python to Access Web Data/W6_Ass_1_Extracting_Data_from_JSON
@@ -0,0 +1,34 @@
1
+import urllib.request, urllib.parse, urllib.error
2
+import json
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 = input("Enter Location: ")
10
+#url = "http://py4e-data.dr-chuck.net/comments_853295.json"
11
+print("Reteriving", url)
12
13
+uh = urllib.request.urlopen(url)
14
+data = uh.read().decode()
15
+print("Reteriving", len(data),"Characters")
16
+#print(data)
17
18
+try:
19
+ js = json.loads(data)
20
21
+except:
22
+ js = None
23
24
+count = 0
25
+sum = 0
26
27
+for x in js['comments']:
28
+ count = count + 1
29
+ sum = sum + x['count']
30
31
+print("Count:",count)
32
+print("Sum:",sum)
33
34
0 commit comments