From 20b40562b58aca5c05a21eea18abe3db4a7b2752 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 19 Apr 2024 03:21:35 +0530 Subject: [PATCH] fix: return scrapedData after crawlee.run --- scraper/src/scraper.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scraper/src/scraper.js b/scraper/src/scraper.js index 87ab9ee6..f9f93d76 100644 --- a/scraper/src/scraper.js +++ b/scraper/src/scraper.js @@ -1,28 +1,25 @@ import { PlaywrightCrawler } from 'crawlee'; async function scrapeData(url, selectors, waitForSeconds = 2) { + const scrapedData = []; const crawler = new PlaywrightCrawler({ requestHandler: async ({ page }) => { await page.goto(url); - // Wait for specific time (optional) await page.waitForTimeout(waitForSeconds * 1000); console.log('Received selectors:', selectors); - const scrapedData = []; for (const selector of selectors) { const elementData = await page.$$eval(selector, elements => elements.map(el => el.textContent.trim())); scrapedData.push(...elementData); } console.log('Scraped data:', scrapedData); - - return { data: scrapedData }; }, }); - await crawler.run([{ url }]); + return scrapedData; } -export default scrapeData \ No newline at end of file +export default scrapeData; \ No newline at end of file