Я написал этот фрагмент кода, но не могу получить ссылки:
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const countries = ['us', 'gb', 'ca', 'au', 'de', 'nz', 'albania', 'nl', 'is'];
const pia = 'https://www.privateinternetaccess.com/pages/network/'
await page.goto(pia);
for (let i = 0; i < countries.length; i++) {
let el = document.querySelectorAll(`#${countries[i]} > div > div > div.modal-body > div > .subregion > center > .hostname`);
for (let j = 0; j < el.length; j++) {
let url = `htpp://${el[j].innerText}:8888/speedtest`;
console.log(url);
}
}
await browser.close();
})();
Дело в том, что когда я вставляю «страны [...]» и for-l oop в консоли браузера он работает нормально, но когда я попробовал его из Node, он выдает большую ошибку, даже если он печатает всю страницу, если я использую функцию «await page.content ()»:
(node:16300) UnhandledPromiseRejectionWarning: ReferenceError: document is not defined
at C:\Users\jason\Desktop\pptr\script.js:15:17
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:16300) 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:16300) [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.
Я думал, что это может быть способ нацеливания на элементы, но опять же он отлично работает в консоли браузера. Что мне не хватает? Любая помощь приветствуется! Спасибо!