Bonjour , j'ai coder un crawler sont probleme c'est qu'il n'est pas récursif bien qu'il est été prévue a cette effet , en fait il ce bloque sur la première donné qui lui arrive.

disont que @_ contient www.free.fr et clubic.com ben il ce bloque sur www.free.fr


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/perl -w
use strict;
use URI::URL;
use HTTP::Request;
use HTTP::Response;
use HTTP::Cookies;
require LWP::Parallel::RobotUA;
use HTML::Parse qw(parse_html);
use WWW::RobotRules;
 
#===========================================================================#
#                          Begin of configuration                           #
#===========================================================================#
 
 
$| = 1;                                    # Buffer
my $arg;
my $VERSION = "Bot/1.1";                  # Nom du robot
 
my $ua = LWP::Parallel::RobotUA->new('Mozilla/5.0 (compatible; Bot/1.1', 'bot@robotx.com');
   $ua->delay(0);
   $ua->max_hosts(400);                                                                   # sets maximum number of locations accessed in parallel
   $ua->max_req(400);                                                                     # sets maximum number of parallel requests per host
   $ua->wait(0);
   $ua->max_redirect(8000000000);
   $ua->protocols_allowed( [ 'http' ] );
   $ua->protocols_forbidden( [ 'file', 'mailto', 'https', 'ftp', 'socks', 'gopher'] );
   $ua->requests_redirectable( [ 'HEAD' ] );
   $ua->timeout(4);
   $ua->env_proxy;
   $ua->redirect(1);                                   # follow redirects
 
   my $cookie_jar = HTTP::Cookies->new(
    file => 'lwp_cookies.dat',
    autosave => 1,
  );
 
   $ua->cookie_jar($cookie_jar);
 
 
#===========================================================================#
#                               The Robot                                   #
#===========================================================================#
 
my %urls;
 
@urls{ @ARGV } = (1) x @ARGV;
 
foreach my $link ( keys %urls ){
  &robot($link);
}
 
 
sub robot
{
 foreach my $link ( @_ ) {
 
 my $link = $_[0];
 
   my $req = HTTP::Request->new( 'GET', $link );
 
     $req->header('Accept' => [
                     qw(
                      text/html  application/xhtml+xml application/msexcel
                      application/msword application/pdf application/rtf
                      application/x-javascript application/x-httpd-php
                      text/rtf text/nux application/sxc application/sxw
                      application/sxd application/mdi application/x-httpd-asp
                      application/x-httpd-aspx application/x-httpd-mspx
                      application/x-httpd-cfm application/x-httpd-jthml
                      application/x-httpd-pm )
 
    ]
);
 
 
 
 my $res = $ua->request($req, $arg, 4096);
 
if ($res->is_success) {
 
    my ($code, %page, $base);
 
     $code = $res->content;
 
 
     $base = $res->base;
 
          %page = (
 
 
            result => [
 
                         "$code", "$link"
 
                      ]
 
 
            );
 
            print "$page{'result'}->[0]\n";
            print "$page{'result'}->[1]\n";
 
        my $extor = extor_links($code,$base);
 
        robot($extor);
 
  }
 }
}
 
 
 
 
#===========================================================================#
#                               Extract links                               #
#===========================================================================#
 
 
sub extor_links
{
my($url, %saw, @urls);
 
  my $html=$_[0];
  my $base=$_[1];
 
  foreach ($html) {
 
    my $ht_tree = parse_html($_[0]);
    my ($linkpair, $fqurl);
 
      foreach $linkpair (@{$ht_tree->extract_links(qw<a>)}) {
        my($link,$elem) = @$linkpair;
         push(@urls, $fqurl)
             unless $saw{ $fqurl = url($link,$base)->abs->as_string }++;
    }
 
     # print join("\n", sort keys %saw), "\n";
 
       my $urlx = join("\n", sort keys %saw), "\n";
 
      return $urlx;
  }
}

Merci de votre aide