php - DOMXPath query returns zero results -
i'm xpath newbie. have tested query xpath firefox plugin returns perfect result. when ran query in php , var_dump(), no results. output similar to:
class domnodelist#4 (0) { }
php accepts expression valid. far i've removed tbody that's part of browser-generated query. in addition i've tried query ("*") without result. else can try? query below
$page = curl_exec($ch); # close php/curl session curl_close($ch); // create new php dom document $dom = new domdocument; // load html curl request document model @$dom->loadhtml($page); $xpath = new domxpath($dom); //$tablerows = $xpath->query("//id('divresults')/x:table/x:tbody/x:tr"); //$tablerows = $xpath->query("id('divresults')/table/tbody/tr"); //$tablerows = $xpath->query('/*'); $tablerows = $xpath->query('*'); var_dump($tablerows);
for reason, var_dump() does'nt work. here's code gets job done.
$dom = new domdocument; if (!$dom->loadhtml($page)) throw new exception (implode (",", libxml_get_errors())); $xpath = new domxpath($dom); $entries = $xpath->query($xpathexpr); if (!$entries) throw new exception ("xpath evaluation error"); foreach ($entries $entry) echo "name: {$entry->nodename}<br/>path: ".$entry->getnodepath()."<br/>value: {$entry->nodevalue}";
Comments
Post a Comment