I'm trying to filter an array that contains a bunch of urls. I need to return the urls that only contain the word "media-release".
It currently just sends back the error.
Although I tried removing my package-lock.json, it still doesn't work.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.cbp.gov/newsroom/media-releases/all');
const data = await page.evaluate(() => {
const nodeList = document.getElementsByClassName('survey-processed');
const urls = [];
for (i=0; i<nodeList.length; i++) {
urls.push(document.getElementsByClassName('survey-processed')[i].href);
}
const regex = new RegExp('/media-release\\b', 'g');
const links = urls.filter(element => element.match(regex));
return links;
});
console.log(data);
await browser.close();
})();
error (node:10208) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read property 'match' of undefined at puppeteer_evaluation_script:11:50 at Array.filter () at puppeteer_evaluation_script:11:24 at ExecutionContext._evaluateInternal (C:\Users\Documents\\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:217:19) at processTicksAndRejections (internal/process/task_queues.js:86:5)