Using perl Syntax Highlighting
#!/usr/bin/perl -w
use strict;
use HTTP::Request;
require LWP::Parallel::UserAgent;
my $pua = LWP::Parallel::UserAgent->new();
$pua->in_order (1); # handle requests in order of registration
$pua->duplicates(1); # ignore duplicados
$pua->timeout (100); # segundos
$pua->redirect (0); # sigue las redirecciones
$pua->max_hosts(4); # maximo numero de hosts paralelos
$pua->max_req (1); # maximo numero de requests paralelos
open (INDICE,"indice.txt"); #Abro el archivo que contiene las urls
my @reqs = <INDICE>;
foreach my $req (@reqs) {
print "Registering '".$req->url."'\n";
my $response = $pua->request($req);
my $content = $response->content();
print $response->code ,":" , $response->message,"\n";
}
use strict;
use HTTP::Request;
require LWP::Parallel::UserAgent;
my $pua = LWP::Parallel::UserAgent->new();
$pua->in_order (1); # handle requests in order of registration
$pua->duplicates(1); # ignore duplicados
$pua->timeout (100); # segundos
$pua->redirect (0); # sigue las redirecciones
$pua->max_hosts(4); # maximo numero de hosts paralelos
$pua->max_req (1); # maximo numero de requests paralelos
open (INDICE,"indice.txt"); #Abro el archivo que contiene las urls
my @reqs = <INDICE>;
foreach my $req (@reqs) {
print "Registering '".$req->url."'\n";
my $response = $pua->request($req);
my $content = $response->content();
print $response->code ,":" , $response->message,"\n";
}
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4
El archivo indice.txt contiene:
- Código: Seleccionar todo
HTTP::Request->new('GET', http://www.google.es)
HTTP::Request->new('GET', http://www.yahoo.es)
HTTP::Request->new('GET', http://www.msn.com)
HTTP::Request->new('GET', http://www.mtv.es)
El error que devuelve:
- Código: Seleccionar todo
Can't use 'HTTP::Request->new('GET', http://www.google.es)' as an HTTP::Request
object. Ignoring at C:\Practicas Perl\Leecher\temp_recode.pl line 73
Can't call method "content" without a package or object reference at C:\Practica
s Perl\Leecher\temp_recode.pl line 74, <INDICE> line 4.
Sin embargo el siguiente ejemplo tomado de CPAN funciona perfectamente:
Using perl Syntax Highlighting
require LWP::Parallel::UserAgent;
use HTTP::Request;
# shortcut for demo URLs
my $url = "http://localhost/";
my $reqs = [
HTTP::Request->new('GET', $url),
HTTP::Request->new('GET', $url."homes/marclang/"),
];
my $pua = LWP::Parallel::UserAgent->new();
$pua->in_order (1); # handle requests in order of registration
$pua->duplicates(0); # ignore duplicates
$pua->timeout (2); # in seconds
$pua->redirect (1); # follow redirects
foreach my $req (@$reqs) {
print "Registering '".$req->url."'\n";
if ( my $res = $pua->register ($req) ) {
print STDERR $res->error_as_HTML;
}
}
my $entries = $pua->wait();
foreach (keys %$entries) {
my $res = $entries->{$_}->response;
print "Answer for '",$res->request->url, "' was \t", $res->code,": ",
$res->message,"\n";
}
use HTTP::Request;
# shortcut for demo URLs
my $url = "http://localhost/";
my $reqs = [
HTTP::Request->new('GET', $url),
HTTP::Request->new('GET', $url."homes/marclang/"),
];
my $pua = LWP::Parallel::UserAgent->new();
$pua->in_order (1); # handle requests in order of registration
$pua->duplicates(0); # ignore duplicates
$pua->timeout (2); # in seconds
$pua->redirect (1); # follow redirects
foreach my $req (@$reqs) {
print "Registering '".$req->url."'\n";
if ( my $res = $pua->register ($req) ) {
print STDERR $res->error_as_HTML;
}
}
my $entries = $pua->wait();
foreach (keys %$entries) {
my $res = $entries->{$_}->response;
print "Answer for '",$res->request->url, "' was \t", $res->code,": ",
$res->message,"\n";
}
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
Yo lo que intento es tomar de un txt los hosts, pero no sé por qué no funciona... ¿alguien se le ocurre algo?. Saludos.