PHP 〓〓〓〓获取网页所有链接
[导读]:以下代码用于采集页面时,获取网页中所有的链接,并循环输出: $html = file_get_contents('http://www.runoob.com'); $dom = new DOMDocument();@$dom-loadHTML($html); // grab all the on the page$xpath = new DO...
以下代码用于采集页面时,获取网页中所有的链接,并循环输出:
$html = file_get_contents('http://www.runoob.com'); $dom = new DOMDocument(); @$dom->loadHTML($html); // grab all the on the page $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); echo $url.'<br />'; }
本文来自投稿,不代表微盟圈立场,如若转载,请注明出处:https://www.vm7.com/a/ziyuan/111591.html