- //获取指定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;$ilength;$i++){
- $href = $hrefs->item($i);
- $url = $href->getAttribute('href');
- if(substr($url,0,4) == 'http') echo $url.'
';
- }
- }
复制代码
|