Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Created February 7, 2024 04:32
Show Gist options
  • Save fsndzomga/a8b33c84472de52e264815d1d13bb663 to your computer and use it in GitHub Desktop.
Save fsndzomga/a8b33c84472de52e264815d1d13bb663 to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer');
// Custom delay function
function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time);
});
}
async function countHappyScribeJavaScript(url) {
const browser = await puppeteer.launch({ headless: "new" });
const page = await browser.newPage();
await page.goto(url);
await delay(2000);
const htmlContent = await page.content();
const count = (htmlContent.match(/Happy Scribe/g) || []).length;
console.log(`Happy Scribe appears ${count} times.`);
await browser.close();
}
countHappyScribeJavaScript("https://www.happyscribe.com");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment