php获取URL页面全部超链接地址

评论2,521

php获取URL页面全部超链接地址

php获取URL页面全部超链接地址

 

<?php
$html = file_get_contents('https://s.taobao.com/search?q=windwos');
$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 />';
}

 最后更新:2022-6-10

发表评论