From 6a597daa427ec4f9800255b4904e7b6585364b7a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 19 Aug 2024 00:17:38 +0530 Subject: [PATCH] feat: handle next click pagination on server --- maxun-core/src/interpret.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/maxun-core/src/interpret.ts b/maxun-core/src/interpret.ts index 1ac624da..b7336c9a 100644 --- a/maxun-core/src/interpret.ts +++ b/maxun-core/src/interpret.ts @@ -394,17 +394,15 @@ export default class Interpreter extends EventEmitter { case 'clickNext': const nextButton = await page.$(config.pagination.selector); if (!nextButton) { - return allResults; - } - - // Capture the current URL to check if it changes after clicking next - const currentURL = page.url(); - - await Promise.all([ - nextButton.click(), - page.waitForNavigation({ waitUntil: 'load' }) // Wait for page navigation - ]); - break; + const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config); + allResults = allResults.concat(finalResults); + return allResults; + } + await Promise.all([ + nextButton.click(), + page.waitForNavigation({ waitUntil: 'networkidle' }) + ]); + break; case 'clickLoadMore': const loadMoreButton = await page.$(config.pagination.selector); if (!loadMoreButton) {