code:
lifeWithoutPlasticRouter.addHandler('LIFE_WITHOUT_PLASTIC_PRODUCT', async ({ page, request }) => {
try {
await page.goto(page.url(), { waitUntil: 'domcontentloaded' })
console.log('Scraping products');
const storeName = 'Life Without Plastic';
const title = await page.$eval('h1.product-title', (el) => el.textContent?.trim() || '');
let image = await page.$eval('a.product-image', (img) => img.getAttribute('href'));
let description = await page.$$eval('div.product-description-wrapper p', (paragraphs) => {
return paragraphs.map((p) => p.textContent?.trim()).join(' ');
});
let salePrice = await page.$eval('span.price-value', (el) => el.textContent?.trim() || '');
let newTag = await page.$eval('span.price-ns', (el) => el.textContent?.trim() || '');
let originalPrice = salePrice;
if(newTag){
originalPrice = newTag;
}else{
return
}
originalPrice = originalPrice.replace("$", "")
originalPrice = originalPrice.replace("USD", "")
salePrice = salePrice.replace("$", "")
salePrice = salePrice.replace("USD", "")
const shippingInfo = 'Free Shipping on orders above $100';
...
});