Forum Replies Created

  • To scrape the product price, you can use Puppeteer to extract the price located in a span or div with a class related to pricing. Ensure that the element containing the price has fully loaded by waiting for the selector to appear. Once loaded, you can extract the price text and format it for use.

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://example.com/product-page');
        const price = await page.$eval('.product-price', el => el.innerText);
        console.log('Product Price:', price);
        await browser.close();
    })();
    
  • For scraping stock availability, Puppeteer is ideal for extracting information like “in stock” or “out of stock” text. Once the product page loads, find the availability status in a div or span with a specific class. Using page.$eval(), you can target that specific element to check whether the product is available for purchase.

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://www.tops.co.th/en/product-page');
        const availability = await page.$eval('.product-availability', el => el.innerText);
        console.log('Availability:', availability);
        await browser.close();
    })();