Find All Links on a Page


/ Published in: PHP
Save to your folder(s)

Here's the basic principal behind spiders. (ex: <a href="http://giochiflash.123homepage.it">Giochi Flash</a> $html = file_get_contents('http://www.example.com');


Copy this code and paste it in your HTML
  1. $html = file_get_contents('http://www.example.com');
  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. }

URL: giochiit

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.