News Feed Forums General Web Scraping Scrape product name, price, and stock from Tops Thailand using Puppeteer?

  • Scrape product name, price, and stock from Tops Thailand using Puppeteer?

    Posted by Jove Benton on 12/11/2024 at 11:42 am

    To scrape the product name from Tops Thailand, you can use Puppeteer to open the product page and locate the div or h1 tag containing the name. The product name is usually found in a specific class within these tags. After waiting for the page to load fully, use page.$eval() to extract the inner text.

    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 productName = await page.$eval('.product-name', el => el.innerText);
        console.log('Product Name:', productName);
        await browser.close();
    })();
    
    Astghik Kendra replied 1 week, 3 days ago 4 Members · 3 Replies
  • 3 Replies
  • Osman Devaki

    Member
    12/11/2024 at 12:09 pm

    To handle responses, I use the -i flag to include headers in the output or redirect the response to a file for analysis. This helps debug issues with the request.

  • Coronis Osmond

    Member
    12/12/2024 at 10:19 am

    To scrape the price from Tops Thailand, you need to identify the tag that contains the price information, often a span or div class. With Puppeteer, you can use page.$eval() to grab the price after waiting for the content to load. Handling product price data ensures you get the correct information for each product.

    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 price = await page.$eval('.product-price', el => el.innerText);
        console.log('Price:', price);
        await browser.close();
    })();
    
  • Astghik Kendra

    Member
    12/12/2024 at 10:52 am

    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();
    })();
    

Log in to reply.