<jupyter_start><jupyter_text>Getting the content of a simple web page<jupyter_code># Get the webpage
response = requests.get('https://www.bloomberg.com/asia')
# Get the attributes
dir(response)
response.status_code<jupyter_output><empty_output><jupyter_text>* 200 : Success* 401 : Unauthorised* 400 : Bad request* 403 : Forbidden* 404 : Not found* 500 : Internal server error<jupyter_code>response.headers # examine the nature of content returned
response.text # looks garbled because this is the actual text<jupyter_output><empty_output><jupyter_text>Getting actual JSON data<jupyter_code>api_response = requests.get('https://eservices.mas.gov.sg/api/action/datastore/search.json?resource_id=d3aedcad-ad7a-4172-90eb-407ab4c50096&limit=5')
# json allows us to access the json data as a dict
data = api_response.json()
data.keys()<jupyter_output><empty_output><jupyter_text>We can continue to drill down<jupyter_code>data['result']
len(data['result'])
data['result'].keys()
len(data['result']['records'])
for i in range(len(data['result']['records'])):
    print(data['result']['records'][i])<jupyter_output>{'end_of_year': '1988', 'preliminary': '0', 'eur_sgd': None, 'gbp_sgd': '3.4929', 'usd_sgd': '1.9462', 'aud_sgd': '1.6645', 'cad_sgd': None, 'cny_sgd_100': None, 'hkd_sgd_100': '24.92', 'inr_sgd_100': None, 'idr_sgd_100': None, 'jpy_sgd_100': '1.5464', 'krw_sgd_100': None, 'myr_sgd_100': '71.75', 'twd_sgd_100': None, 'nzd_sgd': None, 'php_sgd_100': None, 'qar_sgd_100': None, 'sar_sgd_100': None, 'chf_sgd': '1.2865', 'thb_sgd_100': None, 'aed_sgd_100': None, 'vnd_sgd_100': None, 'feeds_flatstore_entry_id': '22936', 'timestamp': '1507792511', 'feeds_entity_id': None}
{'end_of_year': '1989', 'preliminary': '0', 'eur_sgd': None, 'gbp_sgd': '3.0467', 'usd_sgd': '1.8944', 'aud_sgd': '1.5021', 'cad_sgd': None, 'cny_sgd_100': None, 'hkd_sgd_100': '24.26', 'inr_sgd_100': None, 'idr_sgd_100': None, 'jpy_sgd_100': '1.3220', 'krw_sgd_100': None, 'myr_sgd_100': '70.14', 'twd_sgd_100': None, 'nzd_sgd': None, 'php_sgd_100': None, 'qar_sgd_100': None, 'sar_sgd_100': None, 'chf_sgd': '1.2315', 'thb_sgd[...]
{'fraction_non_alphanumeric': 0.1875, 'fraction_numerical': 0.09564393939393939, 'mean_word_length': 8.068669527896995, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '496665', 'license': 'MIT', 'n_tokens_mistral': 1019, 'n_tokens_neox': 889, 'n_words': 172, 'path': 'notebook/Requests_Stub.ipynb', 'repo_name': 'playgrdstar/docker_datalab', 'size': '2112'}