Skip to content

Instantly share code, notes, and snippets.

@utilmind
Last active February 10, 2024 03:18
Show Gist options
  • Save utilmind/1bd09c2f7a797a9caff6d5a71f2ff65c to your computer and use it in GitHub Desktop.
Save utilmind/1bd09c2f7a797a9caff6d5a71f2ff65c to your computer and use it in GitHub Desktop.
Check available 2-letter names on "clusters" in NodeJS, using Puppeteer to parse JavaScript-generated content
(async () => {
const puppeteer = require('puppeteer'),
fs = require('fs').promises,
// Generate 2-letter combinations
generateCombinations = x => {
const combinations = [],
// Small latin letters and digits
characters = [...Array(26).keys()].map(i => String.fromCharCode(i + 97))
.concat([...Array(10).keys()].map(i => i.toString()));
// Generate combinations
characters.forEach(char1 => {
characters.forEach(char2 => {
combinations.push(char1 + char2);
});
});
return combinations;
},
// Output all combinations
allCombinations = generateCombinations(),
startFrom = "wt"; // start checking from this combination. Can be empty or false to check all possible combinations.
// GO!
let browser, html,
started;
for (let i in allCombinations) {
let combination = allCombinations[i];
console.log(combination);
if (!started && (!startFrom || combination === startFrom)) {
// initiate the browser
browser = await puppeteer.launch(); // or { headless: false }?
started = 1;
}
if (started) {
// create a new in headless chrome
const page = await browser.newPage();
// go to target website
await page.goto('https://clusters.xyz/bid/' + combination, {
// wait for content to load
waitUntil: 'networkidle0' //'domcontentloaded',
});
// get full page html
html = await page.content();
if (html.indexOf("Name is not available") === -1) {
await fs.writeFile('available_names.txt', combination + "\n", { flag: "a+"});
console.log('FOUND! ' + combination);
}
/* // if you need a screenshot
await page.screenshot({
path: 'screenshot_full.jpg',
fullPage: true
}); */
// Store html content in the reactstorefront file
// await fs.writeFile('last_checked_page.html', html);
//close headless chrome
await page.close();
}
}
process.exit();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment