Finishing requestHandler() request early
Im using Puppeteer requestHandler() and is there a way for me to end the request early instead of waiting for the whole "script" to finish so I could move on to the next URL in the queue?
voidrouter.addHandler('START', async ({ $, crawler, request }) => {
/// ...
if (nothingToScrape) {
return; // sucessfully ends this request and continues in another one
}
// ...
});router.addDefaultHandler(async ({ page, log }) => {
for (let i = 0; i < 10; i++) {
const content = await page.content();
// Check content page
if (/foobar/.test(content)) {
log.info(`Founded foobar!`);
break;
}
await utils.sleep(1000);
}
});