Saya mencari daftar lengkap negara dengan kode negara mereka .
Suka di halaman ini (harus lengkap dan valid):
Saya mencari daftar lengkap negara dengan kode negara mereka .
Suka di halaman ini (harus lengkap dan valid):
Jawaban:
Situs resmi ISO 3166-1 mungkin merupakan sumber terbaru untuk kode dua huruf. Sayangnya, mereka tidak memiliki alpha-3 online, mengutip situs mereka :
Di mana saya dapat menemukan kode negara ISO 3166-1 alpha-3 untuk diunduh gratis di Situs Web ISO 3166 / MA?
Tidak ada tempat Kode alpha-3 tidak tersedia secara gratis. Anda dapat membeli Standar Internasional ISO 3166-1 dari Toko ISO kami. Ini berisi kode tiga huruf.
Agak aneh di era internet, tapi untungnya, ada artikel Wikipedia dengan daftar lengkap dan dokumen resmi PBB yang membahas masalah ini, dengan kode negara .
Memperbarui:
Ada daftar di situs CIA dengan FIPS 10, ISO 3166 Alpha2, ISO 3166 Alpha3, STANAG dan TLD Internet (misalnya, .il atau .uk).
Ringkasan tautan :
Perhatikan bahwa daftar ini berisi entitas non-negara seperti Antartika.
Jika Anda ingin memperbarui daftar secara berkala, Anda dapat mengikis salah satu sumber dan memilah hasilnya ke dalam format yang bermanfaat. Saya sudah melakukannya di sini untuk mengubah daftar kode negara Wikipedia menjadi CSV :
import csv
import urllib2
from BeautifulSoup import BeautifulSoup
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
url = 'http://en.wikipedia.org/wiki/ISO_3166-1'
page = opener.open(url)
soup = BeautifulSoup(page.read())
# "Current Codes" is second table on the page
t = soup.findAll('table', {'class' : 'wikitable sortable'})[1]
# create a new CSV for the output
iso_csv = csv.writer(open('wikipedia-iso-country-codes.csv', 'w'))
# get the header rows, write to the CSV
iso_csv.writerow([th.findAll(text=True)[0] for th in t.findAll('th')])
# Iterate over the table pulling out the country table results. Skip the first
# row as it contains the already-parsed header information.
for row in t.findAll("tr")[1:]:
tds = row.findAll('td')
raw_cols = [td.findAll(text=True) for td in tds]
cols = []
# country field contains differing numbers of elements, due to the flag --
# only take the name
cols.append(raw_cols[0][-1:][0])
# for all other columns, use the first result text
cols.extend([col[0] for col in raw_cols[1:]])
iso_csv.writerow(cols)
Anda dapat menemukan semua (sebagian besar?) Dari dua dan tiga kode huruf di http://download.geonames.org/export/dump/countryInfo.txt - juga memiliki kode numerik dan fips ISO dan info negara lainnya.
Pada banyak distribusi Linux, daftar kode negara iso diinstal secara default di bawah:
/usr/share/xml/iso-codes/iso_3166.xml
Di bawah Fedora / CentOS / RHEL / Debian , paket yang berisi file ini disebut iso-codes
( beranda proyek ).
File XML berisi pemetaan dalam struktur hierarkis:
<iso_3166_entries>
<iso_3166_entry
alpha_2_code="AF"
alpha_3_code="AFG"
numeric_code="004"
name="Afghanistan"
official_name="Islamic Republic of Afghanistan" />
[..]
Itu dapat diubah menjadi format berbasis catatan (misalnya untuk impor basis data) melalui XPath dan shell one liner:
$ xmllint --noout --xpath \
'//iso_3166_entry/@*[name() = "alpha_2_code" or name()="alpha_3_code"]' \
/usr/share/xml/iso-codes/iso_3166.xml \
| sed 's/alpha_2/\nalpha_2/g' \
| awk -F'"' 'OFS="," {print $2,$4}'
Atau, satu dapat menggunakan Python modul pycountry untuk membaca dan mengubah kode dari paket yang, misalnya:
$ pip3 install --user pycountry
$ python3
>>> import pycountry
>>> for i in pycountry.countries:
... print('{},{}'.format(i.alpha2,i.alpha3))
...
AF,AFG
AX,ALA
AL,ALB
[..]
Saya ingin menambahkan pycountry karena Anda memiliki tag python dan sepertinya itulah yang Anda inginkan. Dari dokumen:
Negara ISO, subdivisi, bahasa, mata uang dan definisi skrip dan terjemahannya
pycountry menyediakan basis data ISO untuk standar:
639 Bahasa
3166 Negara
3166-3 Negara yang dihapus
3166-2 Pembagian negara
4217 Mata Uang
15924 Script
Paket termasuk salinan dari pkg-isocodes Debian dan membuat data dapat diakses melalui API Python.
Anda bisa mendapatkan daftar Alpha 2 dan Alpha 3 lengkap (plus info lainnya) dari http://datahub.io/dataset/iso-3166-1-alpha-2-country-codes/resource/9c3b30dd-f5f3-4bbe-a3cb -d7b2c21d66ce Ada tautan ke sana dari http://datahub.io/dataset/iso-3166-1-alpha-2-country-codes
Saya memperbarui skrip @ scw yang menghapus data dari Wikipedia. Sekarang ia menggunakan requests
bukan urllib2
, Beautiful Soup 4 dan menghasilkan JSON alih-alih menulis ke file CSV.
import json
import bs4
import requests
print(json.dumps(
[
{
['name', 'alpha_2', 'alpha_3', 'numeric'][no]:
td.find_all()[-1].text
for no, td in enumerate(row.find_all('td')[:-1])
}
for row in bs4.BeautifulSoup(
requests.get('http://en.wikipedia.org/wiki/ISO_3166-1').text
).find('table', {'class': 'wikitable sortable'}).find_all('tr')[1:]
],
indent=4,
ensure_ascii=False
))
Output JSON seperti:
[
{
"name": "Afghanistan",
"alpha_3": "AFG",
"alpha_2": "AF",
"numeric": "004"
},
{
"name": "Åland Islands",
"alpha_3": "ALA",
"alpha_2": "AX",
"numeric": "248"
},
...
Anda dapat menggunakan kode ini https://classic.scraperwiki.com/scrapers/iso_3166-1/edit/ - lxml selalu lebih cepat daripada BeautifulSoup.
Salin di sini:
import scraperwiki
import lxml.html
import urllib
import datetime
import json
from unidecode import unidecode
def get_html(title):
raw_json = scraperwiki.scrape("http://en.wikipedia.org/w/api.php?action=parse&format=json&page=" + title)
html = json.loads(raw_json)['parse']['text']['*']
return html
page_title = "ISO_3166-1"
html = get_html(page_title)
doc = lxml.html.fromstring(html)
for count, tr in enumerate(doc.cssselect('tr')):
row = [(td.text_content()) for td in tr.cssselect('td')]
if len(row)==5:
for ahref in tr.cssselect('a'):
detailink = ahref.attrib['href']
if detailink.find(':',0,len(detailink)) != -1:
detailink = detailink[6:]
print detailink
now = datetime.datetime.now()
data ={"tmsp_scraped":str(now), "eng_short_name":row[0], "alpha_2_code":row[1], "alpha_3_code":row[2], "numeric_code":row[3], "iso_31662_code":detailink}
scraperwiki.sqlite.save(unique_keys=["eng_short_name"], data=data, table_name="s_iso31661")
html = get_html(detailink)
doc = lxml.html.fromstring(html)
for count, tr in enumerate(doc.cssselect('tr')):
row = [td.text_content() for td in tr.cssselect('td')]
row2 = [td.text_content() for td in tr.cssselect('td')]
if len(row)>0:
if row[0][:2] == detailink[11:]:
now = datetime.datetime.now()
data = {"tmsp_scraped":str(now), "iso_31662_code":detailink, "region_code":row[0], "region_desc":row[1], "region_desc_utf8":row2[1]}
scraperwiki.sqlite.save(unique_keys=["iso_31662_code","region_code"], data=data, table_name="s_iso31662_region")
Satu lagi perpustakaan yang bagus: https://github.com/neuront/python-iso3166
Ada set data hebat di Open Knowledge Foundation yang mencakup ISO 3166 alpha3, alpha2, numeric, dan banyak lainnya.
Saya menemukan database yang sangat bagus di repo github - https://github.com/stefangabos/world_countries
Pada saat menulis repositori terdiri dari json
, csv
, sql
file untuk 22 bahasa dengan kode negara yang berbeda: ISO 3166-1 alpha-3, ISO 3166-1 alpha-2 dan nama lengkap.
Database tampaknya diperbarui secara teratur
Coba daftar ini:
https://gist.github.com/eparreno/205900
Ini memiliki ISO 2 huruf, 3 huruf dan kode numerik dengan nama formulir pendek negara.
php Array dengan 3 huruf kode negara ISO dari artikel Wikipedia
Saya menyalin dan menempel daftar dari Wikipedia dan membuat array. Mungkin kode ini dapat membantu seseorang menghemat waktu, yang ingin membuat berbagai kode negara. Saya tidak terbiasa dengan python, tetapi pembuatan array harus mirip dengan php.
$Countries=array();
array_push($Countries,"ABW");
array_push($Countries,"AFG");
array_push($Countries,"AGO");
array_push($Countries,"AIA");
array_push($Countries,"ALA");
array_push($Countries,"ALB");
array_push($Countries,"AND");
array_push($Countries,"ARE");
array_push($Countries,"ARG");
array_push($Countries,"ARM");
array_push($Countries,"ASM");
array_push($Countries,"ATA");
array_push($Countries,"ATF");
array_push($Countries,"ATG");
array_push($Countries,"AUS");
array_push($Countries,"AUT");
array_push($Countries,"AZE");
array_push($Countries,"BDI");
array_push($Countries,"BEL");
array_push($Countries,"BEN");
array_push($Countries,"BES");
array_push($Countries,"BFA");
array_push($Countries,"BGD");
array_push($Countries,"BGR");
array_push($Countries,"BHR");
array_push($Countries,"BHS");
array_push($Countries,"BIH");
array_push($Countries,"BLM");
array_push($Countries,"BLR");
array_push($Countries,"BLZ");
array_push($Countries,"BMU");
array_push($Countries,"BOL");
array_push($Countries,"BRA");
array_push($Countries,"BRB");
array_push($Countries,"BRN");
array_push($Countries,"BTN");
array_push($Countries,"BVT");
array_push($Countries,"BWA");
array_push($Countries,"CAF");
array_push($Countries,"CAN");
array_push($Countries,"CCK");
array_push($Countries,"CHE");
array_push($Countries,"CHL");
array_push($Countries,"CHN");
array_push($Countries,"CIV");
array_push($Countries,"CMR");
array_push($Countries,"COD");
array_push($Countries,"COG");
array_push($Countries,"COK");
array_push($Countries,"COL");
array_push($Countries,"COM");
array_push($Countries,"CPV");
array_push($Countries,"CRI");
array_push($Countries,"CUB");
array_push($Countries,"CUW");
array_push($Countries,"CXR");
array_push($Countries,"CYM");
array_push($Countries,"CYP");
array_push($Countries,"CZE");
array_push($Countries,"DEU");
array_push($Countries,"DJI");
array_push($Countries,"DMA");
array_push($Countries,"DNK");
array_push($Countries,"DOM");
array_push($Countries,"DZA");
array_push($Countries,"ECU");
array_push($Countries,"EGY");
array_push($Countries,"ERI");
array_push($Countries,"ESH");
array_push($Countries,"ESP");
array_push($Countries,"EST");
array_push($Countries,"ETH");
array_push($Countries,"FIN");
array_push($Countries,"FJI");
array_push($Countries,"FLK");
array_push($Countries,"FRA");
array_push($Countries,"FRO");
array_push($Countries,"FSM");
array_push($Countries,"GAB");
array_push($Countries,"GBR");
array_push($Countries,"GEO");
array_push($Countries,"GGY");
array_push($Countries,"GHA");
array_push($Countries,"GIB");
array_push($Countries,"GIN");
array_push($Countries,"GLP");
array_push($Countries,"GMB");
array_push($Countries,"GNB");
array_push($Countries,"GNQ");
array_push($Countries,"GRC");
array_push($Countries,"GRD");
array_push($Countries,"GRL");
array_push($Countries,"GTM");
array_push($Countries,"GUF");
array_push($Countries,"GUM");
array_push($Countries,"GUY");
array_push($Countries,"HKG");
array_push($Countries,"HMD");
array_push($Countries,"HND");
array_push($Countries,"HRV");
array_push($Countries,"HTI");
array_push($Countries,"HUN");
array_push($Countries,"IDN");
array_push($Countries,"IMN");
array_push($Countries,"IND");
array_push($Countries,"IOT");
array_push($Countries,"IRL");
array_push($Countries,"IRN");
array_push($Countries,"IRQ");
array_push($Countries,"ISL");
array_push($Countries,"ISR");
array_push($Countries,"ITA");
array_push($Countries,"JAM");
array_push($Countries,"JEY");
array_push($Countries,"JOR");
array_push($Countries,"JPN");
array_push($Countries,"KAZ");
array_push($Countries,"KEN");
array_push($Countries,"KGZ");
array_push($Countries,"KHM");
array_push($Countries,"KIR");
array_push($Countries,"KNA");
array_push($Countries,"KOR");
array_push($Countries,"KWT");
array_push($Countries,"LAO");
array_push($Countries,"LBN");
array_push($Countries,"LBR");
array_push($Countries,"LBY");
array_push($Countries,"LCA");
array_push($Countries,"LIE");
array_push($Countries,"LKA");
array_push($Countries,"LSO");
array_push($Countries,"LTU");
array_push($Countries,"LUX");
array_push($Countries,"LVA");
array_push($Countries,"MAC");
array_push($Countries,"MAF");
array_push($Countries,"MAR");
array_push($Countries,"MCO");
array_push($Countries,"MDA");
array_push($Countries,"MDG");
array_push($Countries,"MDV");
array_push($Countries,"MEX");
array_push($Countries,"MHL");
array_push($Countries,"MKD");
array_push($Countries,"MLI");
array_push($Countries,"MLT");
array_push($Countries,"MMR");
array_push($Countries,"MNE");
array_push($Countries,"MNG");
array_push($Countries,"MNP");
array_push($Countries,"MOZ");
array_push($Countries,"MRT");
array_push($Countries,"MSR");
array_push($Countries,"MTQ");
array_push($Countries,"MUS");
array_push($Countries,"MWI");
array_push($Countries,"MYS");
array_push($Countries,"MYT");
array_push($Countries,"NAM");
array_push($Countries,"NCL");
array_push($Countries,"NER");
array_push($Countries,"NFK");
array_push($Countries,"NGA");
array_push($Countries,"NIC");
array_push($Countries,"NIU");
array_push($Countries,"NLD");
array_push($Countries,"NOR");
array_push($Countries,"NPL");
array_push($Countries,"NRU");
array_push($Countries,"NZL");
array_push($Countries,"OMN");
array_push($Countries,"PAK");
array_push($Countries,"PAN");
array_push($Countries,"PCN");
array_push($Countries,"PER");
array_push($Countries,"PHL");
array_push($Countries,"PLW");
array_push($Countries,"PNG");
array_push($Countries,"POL");
array_push($Countries,"PRI");
array_push($Countries,"PRK");
array_push($Countries,"PRT");
array_push($Countries,"PRY");
array_push($Countries,"PSE");
array_push($Countries,"PYF");
array_push($Countries,"QAT");
array_push($Countries,"REU");
array_push($Countries,"ROU");
array_push($Countries,"RUS");
array_push($Countries,"RWA");
array_push($Countries,"SAU");
array_push($Countries,"SDN");
array_push($Countries,"SEN");
array_push($Countries,"SGP");
array_push($Countries,"SGS");
array_push($Countries,"SHN");
array_push($Countries,"SJM");
array_push($Countries,"SLB");
array_push($Countries,"SLE");
array_push($Countries,"SLV");
array_push($Countries,"SMR");
array_push($Countries,"SOM");
array_push($Countries,"SPM");
array_push($Countries,"SRB");
array_push($Countries,"SSD");
array_push($Countries,"STP");
array_push($Countries,"SUR");
array_push($Countries,"SVK");
array_push($Countries,"SVN");
array_push($Countries,"SWE");
array_push($Countries,"SWZ");
array_push($Countries,"SXM");
array_push($Countries,"SYC");
array_push($Countries,"SYR");
array_push($Countries,"TCA");
array_push($Countries,"TCD");
array_push($Countries,"TGO");
array_push($Countries,"THA");
array_push($Countries,"TJK");
array_push($Countries,"TKL");
array_push($Countries,"TKM");
array_push($Countries,"TLS");
array_push($Countries,"TON");
array_push($Countries,"TTO");
array_push($Countries,"TUN");
array_push($Countries,"TUR");
array_push($Countries,"TUV");
array_push($Countries,"TWN");
array_push($Countries,"TZA");
array_push($Countries,"UGA");
array_push($Countries,"UKR");
array_push($Countries,"UMI");
array_push($Countries,"URY");
array_push($Countries,"USA");
array_push($Countries,"UZB");
array_push($Countries,"VAT");
array_push($Countries,"VCT");
array_push($Countries,"VEN");
array_push($Countries,"VGB");
array_push($Countries,"VIR");
array_push($Countries,"VNM");
array_push($Countries,"VUT");
array_push($Countries,"WLF");
array_push($Countries,"WSM");
array_push($Countries,"YEM");
array_push($Countries,"ZAF");
array_push($Countries,"ZMB");
array_push($Countries,"ZWE");
Jika Anda tidak ingin mengkodekan daftar negara (yang saya tidak sarankan, karena banyak berubah) gunakan URL ini dari mana Anda mendapatkan kode 2 huruf dan nama negara dalam format JSON : annsystem.com/api / getCountry
Ini juga termasuk negara-negara anggota PBB dan non-PBB .
Untuk detail dan parameter lihat di sini: flossk.org/en/blog/country-list-good-all
Jika ada pengguna R yang menemukan thread ini, inilah solusi R:
The countrycode
paket berisi daftar lengkap kode negara dalam berbagai format. Dari dokumentasi paket:
Mendukung skema pengkodean berikut: Korelasi karakter Perang, CoW-numeric, ISO3-numeric, ISO3-numeric, ISO2-numeric, numeric IMF, Komite Olimpiade Internasional, FIPS 10-4, FAO numeric, numerik PBB, numerik Bank Dunia, nama negara pendek resmi bahasa Inggris (ISO), benua, wilayah.
Paket ini juga akan mengkonversi antara kode yang berbeda dan dapat mengidentifikasi negara dengan nama standar atau non-standar menggunakan ekspresi reguler.
library(countrycode)
# data frame of country names and codes
head(countrycode_data)
# convert from CoW to ISO3
countrycode(c("ALG","ALB","UKG","CAN","USA"), origin = "cowc", destination = "iso3c")
# ISO2 code from non-standard name
countrycode("Britain", "country.name", "iso2c")
Cukup Gunakan alat Microsoft Excel Power BI untuk mengekstrak data dari Wikipedia. Butuh waktu kurang dari 30 detik untuk membuat goresan excel halaman dan kemudian menyimpannya ke format apa pun yang Anda suka.
Ini adalah utas lama, tetapi layak diperbarui untuk ini.
Forward / Reverse look up pada kode negara Alpha2 dan Alpha3, mengembalikan objek besar per negara yang mencakup kode telepon, mata uang, info iso, info IOC, kode pos, dan lainnya: https://github.com/rolinger/iso-country -data-validasi / pengaturan
Untuk mengambil informasi negara (Nama, karakter ISO 2, karakter ISO 3, ...) Anda dapat menggunakan paket NuGet ini di angrymonkeycloud.com/geography .
Ini adalah klien .Net gratis yang mengambil informasi dari API ISTIRAHAT.