PHP 获取网页所有链接

<?php

$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.runoob.com/w3cnote/php-get-page-link.html

posted @ 2020-09-07 11:32  酷酷的城池  阅读(424)  评论(0编辑  收藏  举报