PHP获取指定URl页面中所有链接
时间:2021-07-01 10:21:17
帮助过:16人阅读
- //获取指定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.'
'; - }
- }
|
PHP, URl