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.
- Beautiful Soup -- HTML page scraping
- Requests -- HTTP for Humans
- ruamel.yaml -- YAML reader/writer
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
Metadata
Release files for iso3166-scraper 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iso3166-scraper-0.0.1.tar.gz | 5.7 kB | Without provenance | Details for iso3166-scraper-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iso3166_scraper-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for iso3166_scraper-0.0.1-py3-none-any.whl |
Total release size: 11.7 kB
Release files / iso3166-scraper-0.0.1.tar.gz
| Download URL | iso3166-scraper-0.0.1.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de258f51095cb2ad847ce4891095c1332dca20a8764194998728dcf26fe3e6a8
|
|
BLAKE2b-256 checksum How to use checksums |
d545793d2dbb60af01c8f3079cfb14206eff7523ceffd134cbb4d43afac3c893
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / iso3166_scraper-0.0.1-py3-none-any.whl
| Download URL | iso3166_scraper-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
913a70ad8ee81554b95e2a2da8385a0ac118f812325aff53fd83a8590fb07549
|
|
BLAKE2b-256 checksum How to use checksums |
79818cebbb8e55517d420cb58c60793f9dd95e7b48f4d5cb173a69ceccf89c86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for iso3166-scraper 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.