Search code examples
phpxpathdomxpath

DOMXpath query returns null


$doc = new DOMDocument();
$doc->loadHTMLFile("https://www.tipico.com/en/wettschein/bslc-bVysdHEpshHRDMQ7E-Y5Q%3D%3D/");

$xpath = new DOMXpath($doc);

$footer = $xpath->query("//div[@class='t_foot']/div[1]/div[1]");
var_dump($footer->item(0)->nodeValue);

Shouldn't this return 48,37? I have other xpath queries which are working, but especially this is not.


Solution

  • The problem is that t_foot is not the only class on the element you are trying to get, so the class name is not equal to the string t_foot. Instead you should select element which class contains t_foot. So XPath expression should be this:

    $footer = $xpath->query('//div[contains(@class, "t_foot")]/div[1]/div[1]');