We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7f864a7 commit ad66c94Copy full SHA for ad66c94
Using_Python_to_Access_Web_Data/extractingDataFromJSON.py
@@ -0,0 +1,23 @@
1
+# prompt for a URL, read the JSON data from that URL using urllib and then parse
2
+# and extract the comment counts from the JSON data, compute the sum of the
3
+# numbers in the file
4
+import urllib.request, urllib.parse,urllib.error
5
+import json
6
+import ssl
7
+
8
+#ignore cert
9
+ctx=ssl.create_default_context()
10
+ctx.check_hostname=False
11
+ctx.verify_mode=ssl.CERT_NONE
12
13
+url=input('Enter URL: ')
14
+if len(url)<1:
15
+ url='http://py4e-data.dr-chuck.net/comments_42.json'
16
+fhand=urllib.request.urlopen(url,context=ctx).read().decode()
17
+formattedJson=json.loads(fhand)
18
+countNum=list()
19
20
+for counts in formattedJson['comments']:
21
+ countNum.append(counts['count'])
22
+print(countNum)
23
+print(sum(countNum))
0 commit comments