Trouver tous liens (urls) dans un site web

Résolu
amdnibrass Messages postés 25 Statut Membre -  
amdnibrass Messages postés 25 Statut Membre -
Bonjour,
j'ai essaiyé d'écrire un script en php qui permet d'afficher tous les liens (internes ou externes ) dans les pages d'un site web .Voiçi mon script

<?php

// It may take a whils to spider a website ...
set_time_limit(10000);

// Inculde the phpcrawl-mainclass
include_once('../PHPCrawl_083/PHPCrawl_083/libs/PHPCrawler.class.php');

// Extend the class and override the handleDocumentInfo()-method
class MyCrawler extends PHPCrawler

{
function handleDocumentInfo(PHPCrawlerDocumentInfo $DocInfo) {

$file = file_get_contents($DocInfo->url);
preg_match_all('/<a[^>]+href="([^"]+)/i', $file, $urls);
# Affichage
foreach($urls as $url){

echo $url;
echo '<br/>';

}

}
}
$crawler = new MyCrawler();
$crawler->setURL("www.tunisie-web.org ");
$crawler->addReceiveContentType("#text/html#");
$crawler->addURLFilterRule("#\.(jpg|gif|png|pdf|jpeg|css|js)$# i");
$crawler->setWorkingDirectory("C:/Users/mayss/Documents/travailcrawl/");
$crawler->go();

?>

mais son execution prend beaucoup de temps et na m'affiche rien :/
j'ai besoin de vs aide

1 réponse

  1. amdnibrass Messages postés 25 Statut Membre
     
    ceçi est le resultat
    0
    1. amdnibrass Messages postés 25 Statut Membre
       
      c bon resolu

      <?php

      // It may take a whils to spider a website ...
      set_time_limit(10000);

      // Inculde the phpcrawl-mainclass
      include_once('../PHPCrawl_083/PHPCrawl_083/libs/PHPCrawler.class.php');

      // Extend the class and override the handleDocumentInfo()-method
      class MyCrawler extends PHPCrawler

      {
      function handleDocumentInfo(PHPCrawlerDocumentInfo $DocInfo) {
      if (PHP_SAPI == "cli") $lb = "\n";
      else {
      $lb = "<br />";
      echo "url du page".'<br/>';
      // Print the URL and the HTTP-status-Code
      echo "Page requested: ".$DocInfo->url." (".$DocInfo->http_status_code.")".$lb;

      // Print the refering URL
      echo "Referer-page: ".$DocInfo->referer_url.$lb;
      $file = file_get_contents($DocInfo->url);
      preg_match_all('/<a[^>]+href="([^"]+)/i', $file, $urls);
      # Affichage
      echo "les liens existants dans la page ".'<br/>';
      foreach($urls as $url){
      for($i=0;$i<sizeof($url);$i++){
      echo $url[$i];

      echo '<br/>';



      }
      }



      }
      }
      }




      $crawler = new MyCrawler();
      $crawler->setURL("www.tunisie-web.org ");
      $crawler->addReceiveContentType("#text/html#");
      $crawler->addURLFilterRule("#\.(jpg|gif|png|pdf|jpeg|css|js)$# i");
      $crawler->setWorkingDirectory("C:/Users/mayss/Documents/travailcrawl/");
      $crawler->go();

      ?>
      0