0

使用 DOMXpath 时出现奇怪的错误。

当我使用 DOMXPath->query 时,第一个调用总是失败,而第二个调用没有。即使我在两个查询中使用相同的 xpath

$html_dom    = new DOMDocument();
@$html_dom->loadHTML($html);
$x_path = new DOMXPath($html_dom);

$nodes = $x_path->query("//table/tr[3]/td[2]");
echo $nodes->length; // returns 0, which is not correct

// Type
$nodes = $x_path->query("//table/tr[3]/td[2]");
echo $nodes->length; // returns 17, which is the correct value

知道为什么会这样吗?

4

0 回答 0