[PHP] 提取页面中所有的链接(DOMDocument) →→→→→进入此内容的聊天室

来自 , 2020-09-18, 写在 PHP, 查看 147 次.
URL http://www.code666.cn/view/7f018eb7
  1. $html = file_get_contents('http://yuncode.net');
  2.  
  3. $dom = new DOMDocument();
  4. @$dom->loadHTML($html);
  5.  
  6. // grab all the on the page
  7. $xpath = new DOMXPath($dom);
  8. $hrefs = $xpath->evaluate("/html/body//a");
  9.  
  10. for ($i = 0; $i < $hrefs->length; $i++) {
  11.        $href = $hrefs->item($i);
  12.        $url = $href->getAttribute('href');
  13.        echo $url.'<br />';
  14. }

回复 "提取页面中所有的链接(DOMDocument)"

这儿你可以回复上面这条便签

captcha