当前位置: 代码迷 >> PHP >> php应用xpath抽取网页超链接
  详细解决方案

php应用xpath抽取网页超链接

热度:141   发布时间:2012-11-03 10:57:43.0
php使用xpath抽取网页超链接
<?php

$html=file_get_contents('http://www.163.com/');
$doc=new DomDocument();
$doc->loadHTML($html);
$xpath=new DOMXpath($doc);
foreach($xpath->query('//a/@href') as $node){
        $link = $node->nodeValue;
        echo $link . "\n";
}

?>