Reputation: 95
I'm trying to download an excel file using getstore from LWP::Simple using this code:
use 5.010;
use strict;
use warnings;
use LWP::Simple qw(getstore);
$xls_link = "http://linksample.com/this/link/auto-downloads/when-link-is-entered.xls";
$file_dir = "file/directory/filename.xls"
getstore($xls_link, $file_dir);
For some reason the file is not downloading. I have used LWP::Simple before with images and they work just fine. The only difference they have with this is that it is an excel file and also the URL auto downloads the file when you enter the URL.
Upvotes: 0
Views: 383
Reputation: 95
Instead of getstore I used WWW::Mechanize instead and also I was getting certification errors from the link
#!/usr/bin/perl
use 5.010;
use strict;
use WWW::Mechanize;
use IO::Socket::SSL qw();
my $xls_link = "http://linksample.com/this/link/auto-downloads/when-link-is-entered.xls";
my $file_dir = "file/directory/filename.xls"
my $mech = WWW::Mechanize->new(ssl_opts => {
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
verify_hostname => 0, # this key is likely going to be removed in future LWP >6.04
});
$mech->get("$xls_link");
$mech->save_content("$file_dir");
Upvotes: 1
Reputation: 2589
Not tested might be helpful for your request.
use strict;
use warnings;
use LWP::Simple;
use WWW::Mechanize;
my $xls_link = $ARGV[0]; #http://linksample.com/this/link/auto-downloads/when-link-is-entered.xls
if (! head($xls_link)) { print "\nError: Provided weblink not available...!\n"; exit; }
else
{
my $file_dir = "c:/file/directory/filename.xls";
if(-e $file_dir) { print "\nError: Provided Directory/File found...!\n"; exit; }
getstore($xls_link, $file_dir);
}
Upvotes: 0