Jan-28-2022, 06:00 PM
The following code will get you the json data and save in a dictionary.
I added the display__dict function only to show the format of the dictionary.
It's not needed for any other reason, and can be removed.
I added the display__dict function only to show the format of the dictionary.
It's not needed for any other reason, and can be removed.
import requests import json nhlstats = {} def display_dict(dictname, level=0): indent = " " * (4 * level) for key, value in dictname.items(): if isinstance(value, dict): print(f'\n{indent}{key}') level += 1 display_dict(value, level) else: print(f'{indent}{key}: {value}') if level > 0: level -= 1 url = "https://statsapi.web.nhl.com/api/v1/game/2021020748/feed/live" response = requests.get(url) if response.status_code == 200: nhlstats = response.json() display_dict(nhlstats) else: print(f"Unable to extract json from {url}")