头像

PHP取得一个页面中的所有链接

2018-04-11 15:32:44 浏览()   来源:http://www.phpdaima.com//jsfx-38.html   评论 ( 0 )   

通过使用此代码段,您可以很容易地提取任何网页上的所有链接。

$html = file_get_contents('http://www.phpdaima.com');  
      
    $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.'  
    ';  
    }


标签: php
广告不存在
评论0

后面还有条评论,点击查看>>

温馨提示:为规范评论内容,垃圾评论一律封号...