This Python script is meticulously crafted to extract ISO-3166 country data from the comprehensive list is available at https://www.iban.com/country-code. The script employs advanced web scraping techniques to programmatically navigate the website and retrieve all current country codes, names, and related information.
It’s important to note that the ISO-3166 country data obtained from websites https://www.iban.com/country-code may be subject to commercial protection. Users should be aware that while the ISO-3166 standard itself is developed and published by the International Organization for Standardization (ISO), the specific presentation and compilation of this data on individual websites could be protected by copyright laws.
Please note that due to restrictions on web scraping and the potential for changes in website structure, it is essential to use this script responsibly and in compliance with the website’s terms of service. Additionally, the script’s functionality is subject to the website’s availability and may require updates if the site’s layout is altered.
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
response = requests.get('https://www.iban.com/country-codes')
raw_data = bs(response.content,'html.parser')
table = raw_data.find('table',{'id':'myTable'})
rows = table.find_all('tr')
headers = [header.get_text() for header in rows[0].find_all('th')]
data = []
for row in rows[1:]:
cols = row.find_all('td')
data.append([col.get_text() for col in cols])
df = pd.DataFrame(data, columns=headers)
df


Leave a Reply