Skip to content

Instantly share code, notes, and snippets.

@ogeday26
Created January 26, 2023 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogeday26/c052dbb87def36d0cf31e0d53e342c7e to your computer and use it in GitHub Desktop.
Save ogeday26/c052dbb87def36d0cf31e0d53e342c7e to your computer and use it in GitHub Desktop.
var script = document.createElement('script');
script.onload = async function() {
var baseUrl = "https://www.nirsoft.net/countryip/";
var parser = new DOMParser();
var {
data: baseDom
} = await axios.get(baseUrl);
var parsedBaseDom = parser.parseFromString(baseDom, 'text/html');
console.table((await Promise.all(Array.from(parsedBaseDom.querySelectorAll("body > table > tbody > tr:nth-child(2) > td:nth-child(3) > table > tbody > tr:nth-child(2) > td:nth-child(2) > p:nth-child(7) > table > tbody > tr > td > a")).map(item => ({
href: item.href,
title: item.textContent
})).map(async item => {
var {
data
} = await axios.get(`${baseUrl}${item.href.split("/")[4]}`);
return {
title: item.title,
data
}
}))).map(item => {
var parsedDom = parser.parseFromString(item.data, 'text/html');
var count = Array.from(parsedDom.querySelectorAll("body > table > tbody > tr:nth-child(2) > td:nth-child(3) > table > tbody > tr:nth-child(2) > td:nth-child(2) > p:nth-child(7) > table > tbody > tr > td:nth-child(3)")).map((item) => +item.textContent).reduce((a, b) => a + b, 0)
return {
title: item.title,
count
}
}))
};
script.src = "https://cdnjs.cloudflare.com/ajax/libs/axios/1.2.5/axios.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
@ogeday26
Copy link
Author

1-> Open chrome new tab
2-> press f12
3-> paste code console
4-> press enter

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment