#!/usr/bin/perl
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use File::Basename;
my $adresse='http://xanpac.de';
my $agent = LWP::UserAgent->new;
my @torrents= ();
sub cb {
my($tag, %attr) = @_;
if ($tag ne 'a') {
return;
}
push(@torrents, values %attr);
}
$extractor = HTML::LinkExtor->new(\&cb);
$ergebnis = $agent->request(HTTP::Request->new(GET => $adresse),sub {$extractor->parse($_[0])});
$basis = $ergebnis->base;
@torrents = map {$_ = url($_, $base)->abs;} @torrents;
foreach (@torrents) {
if($_ =~ /\.torrent$/){
$dl = LWP::UserAgent->new;
$dl->timeout(50);
$antwort = $dl->get($adresse.$_);
$filename = fileparse($_);
if($antwort->is_success) {
open(FH, ">$filename") or die 'datei nicht schreibbar';
print FH $antwort->content;
close(FH);
}
}
}