html - PHP's DomXPath not working the way it was expected -
i'm trying parse html page: http://www.valor.com.br/valor-data/moedas
for simple start, i'm trying td
elements class="left"
, echoing inner texts. i'm struggling understand why code:
$finder = new domxpath($dom); $tds = $finder->query("//*[@class='left']"); foreach ($tds $td) { echo $td->textcontent; }
gives me expected output (a bunch of words belong td
elements aren't worth pasting here) while this:
$finder = new domxpath($dom); $tds = $finder->query("//td[@class='left']"); foreach ($tds $td) { echo $td->textcontent; }
finds nothing. i've tried $finder->query("//td")
td
elements, it's domxpath doesn't recognize tag names. has ever faced same problem?
i have not tested, namespace issue. input page xhtml , has correctly declared xhtml namespace. therefore, need register namespace prefix , use prefix in query.
something this
$finder = new domxpath($dom); $finder->registernamespace("x", "http://www.w3.org/1999/xhtml"); $tds = $finder->query("//x:td[@class='left']"); foreach ($tds $td) { echo $td->textcontent; }
Comments
Post a Comment