News Feed Forums General Web Scraping Scrape product name, price, customer reviews from Magazine Luiza Brazil on Ruby?

  • Scrape product name, price, customer reviews from Magazine Luiza Brazil on Ruby?

    Posted by Elisavet Jordana on 12/12/2024 at 8:40 am

    To scrape the product name from Magazine Luiza Brazil, you can use Ruby with the Nokogiri gem to parse the HTML content. The product name is typically found within an h1 tag with a specific class. After fetching the page content using Net::HTTP, you can parse the HTML and extract the text.

    require 'net/http'
    require 'nokogiri'
    # Fetch the product page
    url = URI('https://www.magazineluiza.com.br/produto-page')
    response = Net::HTTP.get(url)
    # Parse the HTML
    doc = Nokogiri::HTML(response)
    # Extract the product name
    product_name = doc.at_css('h1.product-title').text.strip
    puts "Product Name: #{product_name}"
    
    Rayna Meinrad replied 1 week, 1 day ago 4 Members · 3 Replies
  • 3 Replies
  • Lucianus Hallie

    Member
    12/12/2024 at 11:17 am

    To obtain the price, locate the element containing the pricing information, which is often within a span or div tag with a class indicating price. Using Nokogiri, you can select this element and extract the text, ensuring you handle any currency symbols appropriately.

    require 'net/http'
    require 'nokogiri'
    # Fetch the product page
    url = URI('https://www.magazineluiza.com.br/produto-page')
    response = Net::HTTP.get(url)
    # Parse the HTML
    doc = Nokogiri::HTML(response)
    # Extract the product price
    price = doc.at_css('.product-price').text.strip
    puts "Price: #{price}"
    
  • Lela Sandy

    Member
    12/13/2024 at 7:24 am

    To obtain the price, locate the element containing the pricing information, which is often within a span or div tag with a class indicating price. Using Nokogiri, you can select this element and extract the text, ensuring you handle any currency symbols appropriately.

    require 'net/http'
    require 'nokogiri'
    # Fetch the product page
    url = URI('https://www.magazineluiza.com.br/produto-page')
    response = Net::HTTP.get(url)
    # Parse the HTML
    doc = Nokogiri::HTML(response)
    # Extract the product price
    price = doc.at_css('.product-price').text.strip
    puts "Price: #{price}"
    
  • Rayna Meinrad

    Member
    12/14/2024 at 7:22 am

    To gather customer reviews, identify the section of the page where reviews are listed, typically within div tags with specific classes. Iterate through these elements to extract individual reviews, capturing the review text and any associated metadata such as ratings.

    require 'net/http'
    require 'nokogiri'
    # Fetch the product page
    url = URI('https://www.magazineluiza.com.br/produto-page')
    response = Net::HTTP.get(url)
    # Parse the HTML
    doc = Nokogiri::HTML(response)
    # Extract customer reviews
    reviews = doc.css('.customer-review')
    reviews.each do |review|
      review_text = review.at_css('.review-text').text.strip
      rating = review.at_css('.review-rating').text.strip
      puts "Review: #{review_text} (Rating: #{rating})"
    end
    

Log in to reply.