0

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!

Airea
  • 169
  • 2
  • 11

1 Answers1

0

Your script seems to be fine, but the page you´re trying to enter is examinating the cookies and blocking your script's access.

I believe you should take a look at this: How to avoid being detected as bot on Puppeteer and Phantomjs?

Eduardo Conte
  • 1,145
  • 11
  • 18