1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
open( FIC, "url.txt")||die("Probleme ouverture Fichier en entrée !");
my @urls = <FIC>;
close (FIC);
open( FIC2, ">result.txt")|| die("Probleme ouverture Fichier en entrée !");
#Calcul du nb de passe pour éviter la saturation mémoire
my $cpt=0;
my $i=1;
my $imax = 10;
my $urlsmodulo = $#urls%$imax;
my $urlsmax = ($#urls-$urlsmodulo)/$imax;
my $urlsmaxi=$urlsmax+$urlsmodulo+1;
print (FIC2 "Nombre totales d'urls \$#urls : $#urls\n");
print (FIC2 "Nombre max : $urlsmax\n");
print (FIC2 "Modulo : $urlsmodulo\n");
print (FIC2 "\$urlsmaxi : $urlsmaxi\n");
my $cv = AnyEvent->condvar;
while ( $i <= $imax ) {
select(undef, undef, undef, 0.2); #time 0.2 seconde
$cv = AnyEvent->condvar;
while ( $cpt < $urlsmaxi) {
$cv->begin;
print ( FIC2 "Before the event-loop\n");
my $url=$urls[$cpt];
chomp $url;
print "Start($cpt) $url\n";
print ( FIC2 "Start($cpt) $url\n");
http_request GET => $url, sub {
my ($body, $hdr) = @_;
print ( FIC2 "($cpt) $hdr->{URL}\n");
my $rc=$hdr->{Status};
print ( FIC2 "Code retour : $rc\n");
if ($body =~ /appliok|appliko/i ) { print ( FIC2 "Pattern : $&\n");} else { print ( FIC2 "Pattern : NULL\n");}
if ($body =~ /(serveur : )(\w+)/i ) { print ( FIC2 "Serveur : $2\n");} else { print ( FIC2 "Serveur : NULL\n");}
print ( FIC2 "############$cpt###############\n");
$cv->end;
};
$cpt++;
};
$urlsmaxi=$urlsmaxi+$urlsmax;
$i++;
$cv->recv;
print ( FIC2 "Finish($i) \n");
};
close (FIC2); |
Partager