From e8219963dfdac6ee94971a6db26b2442940a3938 Mon Sep 17 00:00:00 2001 From: justgo129 Date: Thu, 10 May 2018 14:36:45 -0400 Subject: [PATCH 1/3] Added code to parse JSON webpage --- parseWebPage.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 parseWebPage.py diff --git a/parseWebPage.py b/parseWebPage.py new file mode 100644 index 0000000..84c72e8 --- /dev/null +++ b/parseWebPage.py @@ -0,0 +1,12 @@ +# Created in Python 3.6.5 +# Justin Goldstein +# May 10, 2018 +# adapted from +''' +https://stackoverflow.com/questions/12965203/how-to-get-json-from-webpage-into-python-script +''' + +import urllib.request, json +with urllib.request.urlopen("http://199.26.254.151:8080/mudrod-service/SearchVocab?concept=sst") as url: + data = json.loads(url.read().decode()) + print(json.dumps(data, indent=4)) From f6dcd85e427b9de1ac2c9757fc2b748978ad1a03 Mon Sep 17 00:00:00 2001 From: justgo129 Date: Thu, 10 May 2018 15:22:12 -0400 Subject: [PATCH 2/3] added function --- parseWebPage.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/parseWebPage.py b/parseWebPage.py index 84c72e8..4e841f2 100644 --- a/parseWebPage.py +++ b/parseWebPage.py @@ -6,7 +6,13 @@ https://stackoverflow.com/questions/12965203/how-to-get-json-from-webpage-into-python-script ''' -import urllib.request, json -with urllib.request.urlopen("http://199.26.254.151:8080/mudrod-service/SearchVocab?concept=sst") as url: - data = json.loads(url.read().decode()) - print(json.dumps(data, indent=4)) +import urllib.request, json + +myUrl = "http://199.26.254.151:8080/mudrod-service/SearchVocab?concept=sst" + +def parse(myUrl): + with urllib.request.urlopen(myUrl) as url: + data = json.loads(url.read().decode()) + print(json.dumps(data, indent=4)) + +parse(myUrl) From 952df1826658350cd079765a91ea8b224ec7555c Mon Sep 17 00:00:00 2001 From: justgo129 Date: Thu, 10 May 2018 16:50:55 -0400 Subject: [PATCH 3/3] Added output --- parseWebPage.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/parseWebPage.py b/parseWebPage.py index 4e841f2..a9aeb9e 100644 --- a/parseWebPage.py +++ b/parseWebPage.py @@ -1,5 +1,5 @@ # Created in Python 3.6.5 -# Justin Goldstein +# Justgo129 # May 10, 2018 # adapted from ''' @@ -16,3 +16,21 @@ def parse(myUrl): print(json.dumps(data, indent=4)) parse(myUrl) + +# output: +# { +# "graph": { +# "ontology": [ +# { +# "word": "sea surface temperature", + # "weight": 1.0 + # }, + # { + # "word": "ocean temperature", + # "weight": 1.0 + # }, + # { + # "word": "group high resolution sea surface temperature dataset", + # "weight": 0.89 + # }, + # (etc)...