Issue
I try to extract some information with curl command. Using developer tools chrome extract and copy the elements:
outerHTML
<span id="our_price_display" class="" itemprop="price" content="43.35">43,35 €</span>
selector
#our_price_display
XPath
//*[@id="our_price_display"]
I would like to extract the content value (43.35)
How can extract the price via cURL or combined with php-cli's DOMDocument + DOMXPath?
I use for example this url: https://www.primor.eu/valentino/39683-valentino-uomo-intense-edp.html#/volumen-edp_50_ml_vapo
thanks!
Solution
<?php
libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile('https://www.primor.eu/valentino/39683-valentino-uomo-intense-edp.html#/volumen-edp_50_ml_vapo');
$xpath = new DOMXpath($dom);
$nodes = $xpath->query('//span[@id="our_price_display"]/text()');
header("Content-type: text/plain");
foreach ($nodes as $i => $node) {
echo $node->nodeValue, "\n";
}
?>
Answered By - Gilles Quenot