News Feed Forums General Web Scraping Scrape product specifications, seller ratings, delivery option Carrefour Brazil?

  • Scrape product specifications, seller ratings, delivery option Carrefour Brazil?

    Posted by Varda Wilky on 12/12/2024 at 9:38 am

    To extract product specifications from Carrefour Brazil, you can use PHP with cURL to fetch the page content and DOMDocument to parse the HTML. Specifications are often listed in a table or a series of div elements. By navigating through the DOM, you can retrieve these details.

    <?php
    // Initialize cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www.carrefour.com.br/produto-page');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $html = curl_exec($ch);
    curl_close($ch);
    // Load HTML into DOMDocument
    $dom = new DOMDocument;
    libxml_use_internal_errors(true);
    $dom->loadHTML($html);
    libxml_clear_errors();
    // Create XPath to navigate DOM
    $xpath = new DOMXPath($dom);
    // Extract product specifications
    $specs = $xpath->query('//div[@class="product-specifications"]//li');
    foreach ($specs as $spec) {
        echo trim($spec->nodeValue) . "\n";
    }
    ?>
    
    Lela Sandy replied 1 week, 2 days ago 3 Members · 2 Replies
  • 2 Replies
  • Narayanan Syed

    Member
    12/12/2024 at 11:38 am

    To obtain seller ratings, locate the element that displays the seller’s rating, which is often within a span or div tag. Using DOMXPath, you can query this element and extract the rating value.

    <?php
    // Initialize cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www.carrefour.com.br/produto-page');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $html = curl_exec($ch);
    curl_close($ch);
    // Load HTML into DOMDocument
    $dom = new DOMDocument;
    libxml_use_internal_errors(true);
    $dom->loadHTML($html);
    libxml_clear_errors();
    // Create XPath to navigate DOM
    $xpath = new DOMXPath($dom);
    // Extract seller rating
    $rating = $xpath->query('//div[@class="seller-rating"]//span[@class="rating-value"]')->item(0)->nodeValue;
    echo "Seller Rating: " . trim($rating) . "\n";
    ?>
    
    
  • Lela Sandy

    Member
    12/13/2024 at 7:25 am

    To determine delivery options, identify the section of the page that lists available shipping methods and their respective details. By querying this section, you can extract information such as delivery times and costs.

    <?php
    // Initialize cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www.carrefour.com.br/produto-page');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $html = curl_exec($ch);
    curl_close($ch);
    // Load HTML into DOMDocument
    $dom = new DOMDocument;
    libxml_use_internal_errors(true);
    $dom->loadHTML($html);
    libxml_clear_errors();
    // Create XPath to navigate DOM
    $xpath = new DOMXPath($dom);
    // Extract delivery options
    $options = $xpath->query('//div[@class="delivery-options"]//li');
    foreach ($options as $option) {
        echo trim($option->nodeValue) . "\n";
    }
    ?>
    

Log in to reply.