您的位置 首页 php

PHP 获取网页所有链接

以下代码用于采集页面时,获取网页中所有的链接,并循环输出:

$html = file_get_contents(‘

$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 />’;

}

文章来源:智云一二三科技

文章标题:PHP 获取网页所有链接

文章地址:https://www.zhihuclub.com/77750.shtml

关于作者: 智云科技

热门文章

网站地图