Php 返回xpath的空白输出

Php 返回xpath的空白输出,php,xpath,Php,Xpath,我试图列出页面上的所有链接和名称。我一直在为下面的代码获取银行输出 $url="http://www.ciim.in/top-pr-dofollow-social-bookmarking-sites-list-2016"; $html = file_get_contents($url); 节点部分是 $nodes = $my_xpath->query( '//table[@class="social_list"]/tbody/tr' ); foreach( $nodes as

我试图列出页面上的所有链接和名称。我一直在为下面的代码获取银行输出

$url="http://www.ciim.in/top-pr-dofollow-social-bookmarking-sites-list-2016";
$html = file_get_contents($url);
节点部分是

$nodes = $my_xpath->query( '//table[@class="social_list"]/tbody/tr' );

    foreach( $nodes as $node )
    {

    $title  = $my_xpath->evaluate( 'td[1]/a"]', $node );
    $link  = $my_xpath->evaluate( 'td[1]/a/@href"]', $node );

    echo $title.",".$link."<br>";        

    }
$nodes=$my_xpath->query('//table[@class=“social_list”]/tbody/tr');
foreach($node作为$node)
{
$title=$my_xpath->evaluate('td[1]/a“]”,$node);
$link=$my_xpath->evaluate('td[1]/a/@href“]',$node);
echo$title.,“$link.”
”; }
注意:右键点击网站被禁用,我使用开发者工具检查chrome中元素的代码,你的选择器末尾有拖尾
“]
'td[1]/a'.
'td[1]/a/@href'.
,所以将它们改为
td[1]/a
td[1]/a/@href

此外,您还可以通过选择带有
a
td
a
tr
来改进xpath,因此这将忽略没有链接的标题

'//table[@class="social_list"]/tbody/tr[td/a]'
哪个比查询的表[@class=“social_list”]/tbody/tr'

效率更高

$nodes = $xpath->query('//table[@class="social_list"]/tbody/tr/td/a');
在foreach内部获取标题和URL

$title = $node->textContent;
$href = $node->getAttribute('href');
编辑: 我已经测试了这段代码来检索整个表

//Query from parent div
$nodes = $xpath->query('//div[@class="table_in_overflow"]');

foreach ($nodes as $node) {
    $a = $node->getElementsByTagName("a");
    foreach($a as $item) {
      $href =  $item->getAttribute("href");
      $text = $item->nodeValue;
    }
}
代码中的“否”是结尾处的“
”]
。我不明白这应该是什么。但是您的输出是只有空白还是只有第一行?