{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "For retrieving data from the Internet you can use _requests_ library. There are other libraries such as _urllib_ but we will focus on _requests_ as it simplifies a lot of tasks.\n", "\n", "\n", "__requests__ provide multiple functions, here we will look at _get_ function for GET request. \n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import requests \n", "\n", "url = requests.get(\"https://en.wikipedia.org/wiki/List_of_serial_killers_in_the_United_States\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__url__ is an object and contains some attributes such as status code, text, apparent_encoding, encoding, headers, ... \n", "We can use these to access different information of the object." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "requests.models.Response" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(url)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'utf-8'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "url.apparent_encoding" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "200" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "url.status_code" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "
\n", "\n", "