this is my code:
const puppeteer = require('puppeteer');
const DOG_NAME = 'section.adopt.yd-amuta > div.container > div.row.yd-dog-count > div.col-xs-12 > div.adopt-head > div.row> div.col-sm-6.col-xs-12 > div.adopt-breadcrumb-title > h2 > span';
let names = [];
async function run() {
let browser = await puppeteer.launch({
headless: false,
});
let pages = await browser.pages();
let num =1;
for(; num < 6329; num++){
await pages[0].goto('http://www.yad4.co.il/dogs#' + num);
let dogCard = await pages[0].$$('.col-md-4.col-sm-4.col-xs-6');
for (let i = 0; i < dogCard.length; i++) {
await pages[0].waitForSelector('.col-md-4.col-sm-4.col-xs-6');
dogCard[i].click();
}
console.log('Finished clicking.');
let count = 0;
while (count < dogCard.length) {
pages = await browser.pages();
count = pages.length;
}
for (let i = 1; i < dogCard.length; i++) {
let name = await pages[i].evaluate((sel) => {
return document.querySelector(sel).innerHTML;
}, DOG_NAME);
names.push(name);
await pages[i].close();
}
for (let i = 0; i < names.length; i++) {
console.log(`${i + 1}` + ':' + `${names[i]}`);
}
if(num == 6329 ){
browser.close();
}
}
}
run();
I get this error:
"UnhandledPromiseRejectionWarning: Error: Execution context was destroyed, most likely because of a navigation. at rewriteError (C:\Users\Shani Balas\node_modules\puppeteer\lib\ExecutionContext.js:167:15) at process._tickCallback (internal/process/next_tick.js:68:7) -- ASYNC -- at ExecutionContext. (C:\Users\Shani Balas\node_modules\puppeteer\lib\helper.js:111:15) at ElementHandle.evaluate (C:\Users\Shani Balas\node_modules\puppeteer\lib\JSHandle.js:55:42) at ElementHandle. (C:\Users\Shani Balas\node_modules\puppeteer\lib\helper.js:112:23) at ElementHandle._scrollIntoViewIfNeeded (C:\Users\Shani Balas\node_modules\puppeteer\lib\JSHandle.js:181:30) at ElementHandle.click (C:\Users\Shani Balas\node_modules\puppeteer\lib\JSHandle.js:282:16) at ElementHandle. (C:\Users\Shani Balas\node_modules\puppeteer\lib\helper.js:112:23) at run (C:\Users\Shani Balas\Desktop\scraping\appnew.js:20:16) at process._tickCallback (internal/process/next_tick.js:68:7) (node:19268) 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(). (rejection id: 1) (node:19268) [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. (node:19268) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Target closed. at Promise (C:\Users\Shani Balas\node_modules\puppeteer\lib\Connection.js:183:56) at new Promise () at CDPSession.send (C:\Users\Shani Balas\node_modules\puppeteer\lib\Connection.js:182:12) at ExecutionContext._evaluateInternal (C:\Users\Shani Balas\node_modules\puppeteer\lib\ExecutionContext.js:107:44) at ExecutionContext.evaluateHandle (C:\Users\Shani Balas\node_modules\puppeteer\lib\ExecutionContext.js:57:17) at ExecutionContext. (C:\Users\Shani Balas\node_modules\puppeteer\lib\helper.js:112:23) at WaitTask.rerun (C:\Users\Shani Balas\node_modules\puppeteer\lib\DOMWorld.js:570:65) at process._tickCallback (internal/process/next_tick.js:68:7) -- ASYNC -- at Frame. (C:\Users\Shani Balas\node_modules\puppeteer\lib\helper.js:111:15) at Page.waitForSelector (C:\Users\Shani Balas\node_modules\puppeteer\lib\Page.js:1125:29) at run (C:\Users\Shani Balas\Desktop\scraping\appnew.js:19:20) at process._tickCallback (internal/process/next_tick.js:68:7) (node:19268) 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(). (rejection id: 2)"
what do you think I should do?