<jupyter_start><jupyter_text>An API explainer notebookWe use this notebook to explain APIs. Let's say we want to download the Rembrandt page https://en.wikipedia.org/wiki/Rembrandt<jupyter_code>import urllib.request

url = 'http://example.com/'
response = urllib.request.urlopen(url)
data = response.read()      # a `bytes` object
text = data.decode('utf-8')<jupyter_output><empty_output><jupyter_text>Now, use the API to get the page in a format we likehttps://en.wikipedia.org/w/api.php?action=query&titles=Rembrandt&prop=revisions&rvprop=content&format=json<jupyter_code>baseurl = "https://en.wikipedia.org/w/api.php?"
action = "action=query"
title = "titles=Rembrandt"
content = "prop=revisions&rvprop=content"
dataformat ="format=json"

query = "{}{}&{}&{}&{}".format(baseurl, action, content, title, dataformat)
print(query)
wikiresponse = urllib.request.urlopen(query)
wikidata = wikiresponse.read()
wikitext = wikidata.decode('utf-8')
import json
json.loads(wikitext)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1472636815920398, 'fraction_numerical': 0.001990049751243781, 'mean_word_length': 6.921259842519685, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '600816', 'license': 'MIT', 'n_tokens_mistral': 361, 'n_tokens_neox': 353, 'n_words': 69, 'path': 'files/API_check.ipynb', 'repo_name': 'Narcissist1/socialgraphs2020', 'size': '1005'}