Why does PHP XPath not find table elements, although Firefox shows that they exist?

I am trying to pull out the exact table during a "scratch on the Internet". Used cURL to pull out the page in $ html, which succeeds.

Used by Firebug to get the exact XPATH for a table.

Code follows:

$dom = new DOMDocument($html);
$dom->loadHTML($html);

$xpath = new DOMXpath($dom);
$summary = $xpath->evaluate('/html/body/table[5]/tbody/tr/td[3]/table/tbody/tr[8]/td/table');
echo "Summary Length: " . $summary->length;

When executed, the length of $ summary-> is always zero. It does not pull this node table.

Any ideas?

+3
source share
2 answers

Firefox can insert "virtual" tbodyelements into tables that do not have them; Do these elements exist in the source file?

+4
source

Just remove the "/ tbody". From xpath you got from firefox:

.//* [ID = @'']/TBODY/ [1]/ [2]/

:

.//* [ID = @'']/ [1]/ [2]/

+2

Source: https://habr.com/ru/post/1707899/


All Articles