无法获取Xpath来获取nodeList

时间:2013-04-29 13:50:23

标签: php xpath

libxml_use_internal_errors(true);
$url = 'http://thepiratebay.is/browse/200/0/7';
$html = file_get_contents($url);
$dom = new \DOMDocument();
$dom->loadHTML($html);
$x = new \DOMXPath($dom);
$nodeList = $x->query('/html/body/div[2]/div[2]/table/tbody/tr');
foreach ($nodeList as $node) {
    die(var_dump($node));
}

给我错误:

"Invalid argument supplied for foreach()"

不确定为什么xpath不能在该域上运行?

1 个答案:

答案 0 :(得分:1)

如果我是对的,你想要获得该表中的所有标题。我建议一个更简单但更具体的XPath查询,即

$nodeList = $x->query('//div[@class="detName"]');

See it in action