News Feed Forums General Web Scraping Scrape product name, price, rating from Mercado Livre Brazil using Puppeteer?

  • Scrape product name, price, rating from Mercado Livre Brazil using Puppeteer?

    Posted by Audrey Tareq on 12/12/2024 at 6:39 am

    To scrape the product name from Mercado Livre Brazil, you need to navigate to the product page and locate the element containing the title, typically found inside an h1 or span tag with a specific class. Puppeteer lets you extract this information after waiting for the page to load. You can use page.$eval() to grab the name once the content has been rendered.

    const puppeteer = require('puppeteer');
    (async () => {
        // Launch browser and open Mercado Livre product page
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://www.mercadolivre.com.br/product-page');
        // Scrape the product name
        const productName = await page.$eval('h1[]', el => el.innerText);
        console.log('Product Name:', productName);
        await browser.close();
    })();
    
    Eliana Yoel replied 1 week, 1 day ago 3 Members · 2 Replies
  • 2 Replies
  • Rorie Subhadra

    Member
    12/13/2024 at 7:09 am

    To scrape the price from Mercado Livre Brazil, target the element containing the product price, which is typically wrapped in a span tag. Puppeteer enables you to extract text content once the page is fully loaded. You can use page.$eval() to capture the price and ensure it’s formatted correctly with the currency symbol.

    const puppeteer = require('puppeteer');
    (async () => {
        // Open the browser
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://www.mercadolivre.com.br/product-page');
        // Scrape the product price
        const price = await page.$eval('.price-tag-fraction', el => el.innerText);
        console.log('Product Price:', price);
        await browser.close();
    })();
    
  • Eliana Yoel

    Member
    12/14/2024 at 7:07 am

    To scrape the rating from Mercado Livre Brazil, you’ll need to target the element that holds the product’s rating. Ratings are often displayed as star icons or a numeric value. You can use Puppeteer to select the span or div containing the rating and extract it once the page is fully loaded.

    const puppeteer = require('puppeteer');
    (async () => {
        // Open browser and visit product page
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://www.mercadolivre.com.br/product-page');
        // Extract the product rating
        const rating = await page.$eval('.rating-stars', el => el.getAttribute('aria-label'));
        console.log('Product Rating:', rating);
        await browser.close();
    })();
    

Log in to reply.