I have this script below, where I want to download a pdf from a URL
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
my $save = "C:\\Users\\rahard\\Desktop\\";
my $file = get 'http://locationoffile';
How can I save the pdf to the Desktop? (if I click the URL, it will pront me to save a random name file)
Thank you
/edit some sy开发者_高级运维ntax error in $save and edit $file location
Use open
to open a file handle and print to it. Also note that each backslash in $save
must be escaped.
my $save = "C:\\Users\\rahard\\Desktop\\";
my $file = get 'http://file.pdf';
open( FILE, '>', $save . 'filename.pdf' ) or die $!;
binmode FILE;
print FILE $file;
close( FILE );
Could it be that the url is not the origin location of the pdf and you get redirected to them?
If the response of get
is not a valid pdf, it could be the html-content of the redirecting page.
I would test this first.
Therefor I would use WWW::Mechanize
or a similar library.
精彩评论