← All lessons

requests: data from the web

Sign in · Sign up

Lesson 7.11

requests fetches data from websites:

import requests

response = requests.get(url)
print(response.status_code)
print(response.json()[...])   # a field from the task
  • status_code is the response code, 200 means "success";
  • .json() is a method with brackets, it parses the response as JSON.

Downloading from the internet is not needed in this check: the check puts a ready-made response in place, and your program does a normal requests.get(url).

The check sets the address url and the field field. Do requests.get(url), print the response code, then the value of the field field from response.json().

Hint

requests.get(url) returns a response object.

The code is response.status_code, the data is response.json(), and the field is taken by key in square brackets: response.json()["field name"].