How do I return json value from a multithread API call?

I am fairly new to programming. From this code, I am only getting the array of API websites. I would like to get the content from each of these websites.

# list of websites that I am gathering from a function
websites = get_list()


# Retrieve a single page and report the URL and contents
def load_url(url, timeout):
    with urllib.request.urlopen(url, timeout=timeout) as conn:
        return conn.read()

# We can use a with statement to ensure threads are cleaned up promptly
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    # Start the load operations and mark each future with its URL
    future_to_url = {executor.submit(load_url, url, 60): url for url in websites}
    for future in concurrent.futures.as_completed(future_to_url):
        url = future_to_url[future]
        print(url)

Source: Python Questions

LEAVE A COMMENT