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不能在该域上运行?
答案 0 :(得分:1)
如果我是对的,你想要获得该表中的所有标题。我建议一个更简单但更具体的XPath查询,即
$nodeList = $x->query('//div[@class="detName"]');