Почему код на puppeteer не выполняет свою функцию?

есть код

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://etfdb.com/screener/#page=1&structure=ETF&dividend_frequency=Monthly');

    const rows = document.querySelector('div#mobile_table_pills table')
        .querySelectorAll('tbody tr');

    for (const row of rows) {
        const lastCellText = row.querySelector('[data-th="ETFdb Pro"]').innerText;
        if (lastCellText === 'A+' || lastCellText === 'B+') {
            console.log(row.querySelector('[data-th="Symbol"]').innerText);
        }
    }

    await page.screenshot({path: 'etfdb.png'});

    await browser.close();
})();

сделал: npm i, npm i puppeteer, npm i puppeteer-core; он выдает ошибку :

MacBook-Pro-Aleksandr:Новая папка 3 aleksandr$ npm start

> [email protected] start /Users/aleksandr/Desktop/Новая папка 3
> node script.js

(node:31499) UnhandledPromiseRejectionWarning: ReferenceError: document is not defined
    at /Users/aleksandr/Desktop/Новая папка 3/script.js:8:18
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:31499) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:31499) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

если кто знает подскажите как реализовать что бы этот код переходил на следующую страницу и совершал свой функционал там и пока не дойдет до конца.


Ответы (0 шт):