Skip to content

JesseRai/ONS-Weekly-Shipping-Indicators-Scraper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

ONS Weekly Shipping Indicators Scraper

This Python script automatically scrapes the latest Weekly Shipping Indicators dataset from the UK Office for National Statistics (ONS), downloads the latest .xlsx file, and converts all sheets into .csv files.

Features

  • Automatically detects the most recent .xlsx file based on the date in the filename.
  • Downloads the file directly from the ONS website.
  • Converts each Excel sheet into a separate CSV file for easy analysis.

Requirements

  • Python 3.7+
  • requests
  • pandas
  • beautifulsoup4
  • lxml (optional but recommended for better Excel parsing)

Install dependencies using:

pip install requests pandas beautifulsoup4 lxml

Usage

Clone the repository and run:

python ons_shipping_scraper.py

This will:

  1. Print a list of all .xlsx links on the page with their parsed dates.
  2. Download the latest one.
  3. Save each worksheet in the Excel file as a .csv file in the current directory.

File Structure

  • ONS.py: Main Python script.
  • Output: One .csv file per Excel sheet from the downloaded dataset.

Example Output

Detected Excel files with dates:
/economy/.../weeklyshippingindicators060825.xlsx --> 2025-08-06
Downloading the latest file: https://www.ons.gov.uk/economy/.../weeklyshippingindicators060825.xlsx
Saved sheet 'Summary' as CSV: Summary.csv
Saved sheet 'Data' as CSV: Data.csv
...

Notes

  • The script uses regex to detect dates in filenames. If the format changes on the ONS website, it may need adjustment.
  • By default, it saves the Excel file and CSVs in the same directory as the script.

About

Automatically downloads and converts the latest ONS Weekly Shipping Indicators Excel dataset into CSV files.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages