Forum Replies Created

  • Scraping availability from BigC Thailand is similar to scraping the product price, but here you target the availability status, such as “In Stock” or “Out of Stock”. After navigating to the product page, use Puppeteer to extract the availability text by targeting the appropriate element using page.$eval(). This information is often displayed as a simple text string or inside a span.

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://www.bigc.co.th/en/product-page');
        const availability = await page.$eval('.availability-status', el => el.innerText);
        console.log('Availability:', availability);
        await browser.close();
    })();
    
  • 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";
    ?>