Skip to main content

A Python utility that scrapes ISO 3166 country code data from Wikipedia

Project description

iso3166-scraper

A simple utility for scraping ISO-3166 country data from a Wikipedia article that contains all current country codes, names, etc.

In a recent project, I had a need for the ISO 3166 country code data and was disappointed to discover that there really wasn't a good free source for obtaining the data in structured form. I'm sure there's some place where I could spend money with ISO to get this data, but that's not a great option for an open source project with no revenue stream for such expenses.

However, the above referenced Wikipedia article was pretty cleanly structured and easy enough to scrape. The data changes infrequently, so occasionally running this utility to get the latest data seems like a decent compromise. Maybe you'll find it useful too.

This utility scrapes the web page, and outputs the country code data in JSON and YAML formats.

In addition to the basic country data, the script maps the country codes to the corresponding Unicode code points for each country's flag and includes the appropriate escape sequences in a string property of the output data in every format.

This tool is built using some excellent open source components that make creating tools like this really easy.

Installation

This package is available for installation via PyPI and can therefore be installed using pip as follows.

python3 -m pip install iso3166-scraper

Usage

After installation, you can simply run it.

$ iso3166-scraper
retrieving https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
writing JSON file: ./iso3166.json
writing YAML file: ./iso3166.yml

By default, it fetches the Wikipedia article, scrapes the ISO 3166 country data from the page, and produces JSON and YAML output files in the current directory. Using command line options, you can select which output format you want and where to put it. To see all the options, use

iso3166-scraper --help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iso3166-scraper-0.0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iso3166_scraper-0.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file iso3166-scraper-0.0.1.tar.gz.

File metadata

  • Download URL: iso3166-scraper-0.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for iso3166-scraper-0.0.1.tar.gz
Algorithm Hash digest
SHA256 de258f51095cb2ad847ce4891095c1332dca20a8764194998728dcf26fe3e6a8
MD5 a0ef1ab700cf2917ad4b8e5b01c3d50d
BLAKE2b-256 d545793d2dbb60af01c8f3079cfb14206eff7523ceffd134cbb4d43afac3c893

See more details on using hashes here.

File details

Details for the file iso3166_scraper-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for iso3166_scraper-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 913a70ad8ee81554b95e2a2da8385a0ac118f812325aff53fd83a8590fb07549
MD5 771ea4d6054325d501fa7d458b47934c
BLAKE2b-256 79818cebbb8e55517d420cb58c60793f9dd95e7b48f4d5cb173a69ceccf89c86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page