I am working with NodeJS and the Puppeteer library to load a website and then check if a certain text is displayed on the page. I would like to count the number of occurrences of this specific text. Specifically, I would like this search to work exactly in the same manner as how the Ctrl+F
function works in Chrome or Firefox.
Here’s the code I have so far:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
// How do I count the occurrences of the specific text here?
await browser.close();
})();
Can someone please help me with a solution on how to achieve this? Any help would be greatly appreciated. Thanks in advance!