1
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 在该域上不起作用?

4

1 回答 1

1

如果我是对的,您希望获得该表中的所有标题。我建议使用更简单但更具体的 XPath 查询,即

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

看到它在行动

于 2013-04-29T14:15:31.063 回答