I want to search specific text on a webpage using XPath.

<?php
$url = 'http://www.barringtonsports.com/browse/hockey_sticks/show/325/list';
$html = file_get_contents($url);        
$doc = new DOMDocument();
@$doc->loadHTML($html);     
$xpath = new DOMXPath($doc);
$found = $xpath->evaluate("//span[contains(text(),'blablabla')]");
if(!$found){
   echo "NOT FOUND";        
}
else{
    echo "found";
}
?>

it always give the output found as the text blablabla is not in the webpage. where is the problem? Is my evalute expression correct for searching specific text?

有帮助吗?

解决方案

evaluate will not return a boolean for a XPath expression that selects a node, you have to use:

$found = $xpath->evaluate("boolean(//span[contains(text(),'blablabla')])");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top