Skip to content

Instantly share code, notes, and snippets.

@vanwars
Created September 24, 2020 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanwars/6357462cbd6c7c6dd8813cd9807c9a46 to your computer and use it in GitHub Desktop.
Save vanwars/6357462cbd6c7c6dd8813cd9807c9a46 to your computer and use it in GitHub Desktop.
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