Skip to content

Instantly share code, notes, and snippets.

@itslukej
Last active May 6, 2019 01:40
Show Gist options
  • Save itslukej/3da6a14a7c6ca6674d47221d7f977c22 to your computer and use it in GitHub Desktop.
Save itslukej/3da6a14a7c6ca6674d47221d7f977c22 to your computer and use it in GitHub Desktop.
Find the shortest domains on park.io
const tlds = ['io', 'ly', 'to', 'me', 'pro', 'red', 'sh', 'ac', 'vc', 'gg', 'je', 'mn', 'bz', 'ag', 'sc', 'lc'];
const superagent = require('superagent');
const cheerio = require('cheerio');
const word = require('check-word')('en');
function getUrl(tld, page = 1) {
return `https://park.io/domains/index${tld == 'io' ? '' : `/${tld}`}/page:${page}`;
}
async function getDomains(url) {
const resp = await superagent.get(url);
const $ = cheerio.load(resp.text);
return $('table > tbody > tr > td:first-child').map(function() { return $(this).text().trim() }).get();
}
async function getPages(tld) {
const resp = await superagent.get(getUrl(tld, 1));
const $ = cheerio.load(resp.text);
const url = $('.park-module > div> ul > li:last-child > a').attr('href');
return url ? parseInt(url.split(':')[1]) : 1;
}
const init = async function () {
let domains = [];
for (const tld of tlds) {
const pages = await getPages(tld);
const promises = [];
for (let i = 1; i <= pages; i++) {
promises.push(getDomains(getUrl(tld, i)));
}
const tldDomains = await Promise.all(promises).then(ds => ds.reduce((a, b) => a.concat(b), []));
const filtered = tldDomains.filter(domain => word.check(domain.slice(0, -1 - tld.length)));
domains = domains.concat(filtered);
console.log('Processed tld', tld);
}
const sorted = domains.sort((a, b) => b.length - a.length);
sorted.forEach(d => console.log(d));
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment