PHP 获取指定URl页面中所有链接

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    //获取指定URL页面中所有链接  
    function get_url_href($url){  
        $html = file_get_contents($url);  
        $dom = new DOMDocument();  
        @$dom->loadHTML($html);  
        $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');  
            if(substr($url,0,4) == 'http') echo $url.'<br>';  
        }  
    }