Skip to content

Instantly share code, notes, and snippets.

@depperm
Last active December 2, 2023 10:16
Show Gist options
  • Save depperm/9cf8fc6f06ec1c8f9c87457ca64d94ba to your computer and use it in GitHub Desktop.
Save depperm/9cf8fc6f06ec1c8f9c87457ca64d94ba to your computer and use it in GitHub Desktop.
ISO3166 Countries
// https://www.iso.org/iso-3166-country-codes.html > click Online Browsing Platform > 300 results per page
// copy-paste below in console
var table = document.evaluate("/html/body/div[1]/div/div[2]/div/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div[2]/div[3]/table", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var countries=[];
for (var i = 1; i<table.rows.length; i++) {
var row = table.rows[i];
var country={};
for (var j = 0; j<row.cells.length; j++) {
var col=row.cells[j];
switch(j){
case 0:
country.name=col.children[0].textContent;
break;
case 2:
country.code2=col.innerHTML;
break;
case 3:
country.code3=col.innerHTML;
break;
}
}
countries.push(country);
}
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
console.save(countries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment