chore: lint

This commit is contained in:
karishmas6
2024-09-20 23:37:00 +05:30
parent a7a1e9b305
commit 061714fcdc

View File

@@ -408,14 +408,14 @@ export default class Interpreter extends EventEmitter {
case 'scrollUp': case 'scrollUp':
await page.evaluate(() => window.scrollTo(0, 0)); await page.evaluate(() => window.scrollTo(0, 0));
await page.waitForTimeout(2000); await page.waitForTimeout(2000);
const currentTopHeight = await page.evaluate(() => document.documentElement.scrollTop); const currentTopHeight = await page.evaluate(() => document.documentElement.scrollTop);
if (currentTopHeight === 0) { if (currentTopHeight === 0) {
const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config); const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config);
allResults = allResults.concat(finalResults); allResults = allResults.concat(finalResults);
return allResults; return allResults;
} }
previousHeight = currentTopHeight; previousHeight = currentTopHeight;
break; break;
case 'clickNext': case 'clickNext':
@@ -448,33 +448,33 @@ export default class Interpreter extends EventEmitter {
break; break;
case 'clickLoadMore': case 'clickLoadMore':
while (true) { while (true) {
const loadMoreButton = await page.$(config.pagination.selector); const loadMoreButton = await page.$(config.pagination.selector);
if (!loadMoreButton) { if (!loadMoreButton) {
// No more "Load More" button, so scrape the remaining items // No more "Load More" button, so scrape the remaining items
const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config); const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config);
allResults = allResults.concat(finalResults); allResults = allResults.concat(finalResults);
return allResults; return allResults;
} }
// Click the 'Load More' button to load additional items // Click the 'Load More' button to load additional items
await loadMoreButton.click(); await loadMoreButton.click();
await page.waitForTimeout(2000); // Wait for new items to load await page.waitForTimeout(2000); // Wait for new items to load
// After clicking 'Load More', scroll down to load more items // After clicking 'Load More', scroll down to load more items
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)); await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await page.waitForTimeout(2000); await page.waitForTimeout(2000);
// Check if more items are available // Check if more items are available
const currentHeight = await page.evaluate(() => document.body.scrollHeight); const currentHeight = await page.evaluate(() => document.body.scrollHeight);
if (currentHeight === previousHeight) { if (currentHeight === previousHeight) {
// No more items loaded, return the scraped results // No more items loaded, return the scraped results
const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config); const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config);
allResults = allResults.concat(finalResults); allResults = allResults.concat(finalResults);
return allResults; return allResults;
} }
previousHeight = currentHeight; previousHeight = currentHeight;
if (config.limit && allResults.length >= config.limit) { if (config.limit && allResults.length >= config.limit) {
// If limit is set and reached, return the limited results // If limit is set and reached, return the limited results
allResults = allResults.slice(0, config.limit); allResults = allResults.slice(0, config.limit);
break; break;
} }
} }
break; break;
default: default: