I'm trying to scape a website but I cannot find a way to show the results in the console.log. The script I've created is the following:
const puppeteer = require("puppeteer");
(async () => {
try {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(`https://www.coches.net/nuevo/km-0/`);
await page.waitFor(4000);
const news = await page.evaluate(() => {
const urlsArray = Array.from(document.querySelectorAll('.mt-CardAd-link')).map(a => a.href);
return urlsArray;
});
console.log(news);
await browser.close();
console.log("Browser Closed");
} catch (err) {
console.log(err);
await browser.close();
console.log("Browser Closed");
}
})();
While the variable urlsArray works in the devconsole of Chrome, it doesn't when launching the script in the terminal with the previous script. I tried everything but I don't find anything to solve this issue. What I can do to finally be able to show this array with the console.log?
Thank you!