Skip to main content

Module 3: Data from the Web

Note

Not taught in the November–December 2026 ENSEA course. The materials remain here for self-study.

Overview

A lot of data, and some data that exists nowhere else, lives on the web. This module shows how to collect it with Python: calling web APIs and working with the JSON they return, scraping HTML pages with requests and BeautifulSoup, and downloading text at scale from news sites and Wikipedia. It also covers the etiquette and legal questions of collecting data online.

Estimated time: about 3 hours (1 hour lecture, 2 hours hands-on)

Learning objectives

By the end of this module, you should be able to:

  • Explain what an API is, make GET requests with requests, and interpret HTTP status codes.
  • Parse JSON responses into Python objects and pandas DataFrames, and save the results to CSV.
  • Pull indicators from a real data API, such as the World Bank’s World Development Indicators.
  • Inspect a page’s HTML structure, extract text and tables with BeautifulSoup, and clean them into a DataFrame.
  • Tell web scraping from web crawling, and collect data responsibly: prefer an API, respect site terms and rate limits.

Before class

Prerequisites: Python basics, Python dictionaries (JSON maps directly onto them) and basic pandas. Knowing what HTML looks like helps but isn’t required.

Some exercises need a free OpenWeather API key: sign up before class, since new keys can take a few hours to activate.

Lecture slides

Open the slides (Google Slides) Version française

Hands-on

Introduction to Using APIs

Request and parse JSON from the Open Notify, OpenWeather and World Bank APIs.

View Open in Colab Download

Web Scraping 101

Scrape a race-results table with requests and BeautifulSoup and save it as CSV.

View Open in Colab Download

Collecting Text Data from the Web

Scrape news articles and download Wikipedia pages for a list of countries.

View Open in Colab Download

Exercises

To be added.

Further reading