Created
September 24, 2020 14:54
-
-
Save vanwars/6357462cbd6c7c6dd8813cd9807c9a46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib.request | |
my_title = 'Child' | |
my_description = 'metal' | |
requestURL = 'https://www.saferproducts.gov/RestWebServices/Recall?Title={title}&RecallDescription={description}&format=json'.format( | |
title=my_title, description=my_description | |
) | |
print('Retrieving data from...', requestURL) | |
with urllib.request.urlopen(requestURL) as response: | |
html = response.read() | |
data = json.loads(html) | |
# process data: | |
print(len(data)) | |
print('*' * 50) | |
print('Number of results:', data[0]) | |
print('*' * 50) | |
print('Keys:', data[0].keys()) | |
print('*' * 50) | |
print('Injuries:', data[0].get('Injuries')[0].get('Name')) | |
print('*' * 50) | |
print('Hazards:', data[0].get('Hazards')[0].get('Name')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment