| TheAnswer1313 2006-05-30, 7:00 pm |
| hi using perl i tried to download a couple of zip files. They worked
fine but when i went to unzip them, i got that error msg. I have
noticed that when i download the files manually, they are slightly
smaller then when i download them with the script. If anyone can help
me around this issue, it would be great appreciated.
#!/usr/bin/perl -w
use FileHandle;
use LWP::UserAgent;
$ua = LWP::UserAgent ->new;
$baseurl = "http://www.retrosheet.org/";
$league = 'ml';
for ($year = 00; $year <= 05; $year++) {
my $filename = '200' . $year . $league . '.zip';
my $url = $baseurl . '200' . $year . '/200' . $year . $league .
'.zip';
my $req = HTTP::Request ->new(GET => $url);
my $res = $ua ->request($req);
print STDERR "fetching $filename\n";
if ($res ->is_success) {
my $fh = new FileHandle ">$filename";
if (defined $fh) {
print $fh $res ->content;
$fh ->close;
} else {
print STDERR "could not open file $filename: $!\n";
}
}
else {
print STDERR $res ->status_line, "\n";
}
}
|