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";
}
?>