I began to mess around with the Web in Perl. I use Windows, and ActivePerl. I wrote a script, which downloads mp3 files (It's an archive of a radio talkshow, all legal, in case you're wondering :) ) It (in theory)
However the script finds all the links, the array is OK, but downloads only one file. It must be a basic error, but I can't find it. Please point out my mistake, thank you.
use strict;
use warnings;
use WWW::Mechanize;
use LWP::Simple;
use File::Basename;
my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->get("http://something_or_other.html");
my @mp3links = $mech->find_all_links(
tag => "a",
url_regex => qr/\.mp3$/,
);
print "\n";
foreach my $link (@mp3links) {
my $url = $link->url();
my $localfile = basename($url);
my $localpath = "d:\\Downloads\\$localfile";
print "$localfile\n";
getstore($url, $localpath);
}
Oh, sorry guys. This had nothing to do with Perl. My internet connection was rather sh***y, the connection was always lost ehile downloading the first file.