bambawRouter.addHandler('BAMBAW_PRODUCT', async ({ page, request }) => { try { console.log('Scraping products'); const site = 'Bambaw'; const title = await page.$eval('h1.product__title', (el) => el.textContent?.trim() || ''); const descriptions = await ...... const productData = { url: request.loadedUrl, site, title, descriptions, originalPrice, salePrice, shippingInfo, reviewScore, reviewNumber, }; productList.push(productData); console.log('Scraped ', productList.length, ' products') // Read the existing data from the rawData.json file let rawData: any = {}; try { const rawDataStr = fs.readFileSync('rawData.json', 'utf8'); rawData = JSON.parse(rawDataStr); } catch (error) { console.log('Error reading rawData.json:', error); } // Append the new data to the existing data if (rawData.productList) { rawData.productList.push(productData); } else { rawData.productList = [productData]; } // Write the updated data back to the rawData.json file fs.writeFileSync('rawData.json', JSON.stringify(rawData, null, 2)); console.log('rawData.json updated for Bambaw'); } catch (error) { console.log('Error scraping product:', error); bambawQueue.reclaimRequest(request); return; }