Home >Backend Development >PHP Tutorial > php应用xpath抽取网页超链接

php应用xpath抽取网页超链接

WBOY
WBOYOriginal
2016-06-13 13:07:47942browse

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";
}

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article: php怎么调试部署 Next article: PHP 装配