문제

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