News Feed Forums General Web Scraping Scrape product name, price, and rating from a Thai e-commerce site with Node.js?

  • Scrape product name, price, and rating from a Thai e-commerce site with Node.js?

    Posted by Fathima Scilla on 12/11/2024 at 11:31 am

    To scrape the product name from an e-commerce site in Thailand, you can use Puppeteer to launch the page and use page.evaluate() to extract the text from the element containing the product name. This will typically be inside a <div> or <h1> tag with a specific class. Ensure that you wait for the page to load fully before scraping the data.

    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 name = await page.$eval('.product-title', el => el.innerText);
        console.log('Product Name:', name);
        await browser.close();
    })();
    
    Candice Agata replied 1 week, 2 days ago 5 Members · 5 Replies
  • 5 Replies
  • Fathima Scilla

    Member
    12/11/2024 at 11:32 am

    To bypass detection, I use undetected-chromedriver, which prevents Selenium’s presence from being flagged by anti-bot mechanisms. This ensures smoother scraping.

  • Shena Brigid

    Member
    12/11/2024 at 11:57 am

    I implement rotating proxies and delay requests to mimic real user behavior. These strategies help avoid IP bans or rate-limiting by the server.

  • Nagendra Berna

    Member
    12/11/2024 at 12:39 pm

    Storing scraped data in a structured database like PostgreSQL allows for efficient querying and analysis, making it easy to compare browser profiles or track changes over time.

  • Astghik Kendra

    Member
    12/12/2024 at 10:53 am

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

    Member
    12/13/2024 at 6:54 am

    To scrape the product rating, use Puppeteer to find the rating element, which is often inside a div or span containing star icons or numerical ratings. After waiting for the element to load, extract the rating text using page.$eval(). This can help you gather insights into how well a product is reviewed.

    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 rating = await page.$eval('.product-rating', el => el.innerText);
        console.log('Product Rating:', rating);
        await browser.close();
    })();
    

Log in to reply.