tale103108 has asked for the wisdom of the Perl Monks concerning the following question:

I have tried LWP and WWW modules to download a zipped file from a web site. I can connect, login to website and when I go to get the file (URL), it says the URL is not there. When I do this manually, I login and then go to the web page that has the URL for the zipped file. But when I try to download the file, I get the window prompting me to Open, Save or Cancel. I believe this is where my problem is occurring. My general question is does anyone have a simple example of downloading a file (any file) when there is a prompt from the web site to Open, Save or Cancel? I most graciously appreciate your guidance and monkish wisdom.

Replies are listed 'Best First'.
Re: download ZIP file from web
by Gangabass (Vicar) on May 27, 2010 at 04:59 UTC

    Can you show your code?

    Also you can try to disable Javascript in your browser and clear cookies and after that try to get file you need again (from the browser). If you get file than it's not Javascript problem (something wrong with you code)...

Re: download ZIP file from web
by bluescreen (Friar) on May 26, 2010 at 23:39 UTC
    Usually the Open, Save & Cancel pop-up comes from the browser, what is the status code you get from LWP? In any case the following snippet should get the file for you:
    use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new; #my $req = HTTP::Request->new(GET => 'http://search.cpan.org/CPAN/auth +ors/id/G/GA/GAAS/libwww-perl-5.836.tar.gz'); my $req = HTTP::Request->new(GET => 'http://usename:password@host/path +/to/file.zip'); my $res = $ua->request($req); if ($res->is_success) { # here put what you want to do with the file # print $res->content; # or # open( my $file, '> file.zip'); # print $file $res->content; # close($file); } else { print STDERR $res->status_line; }
Re: download ZIP file from web
by aquarium (Curate) on May 27, 2010 at 00:16 UTC
    Most websites have at least a bit of javascript/etc code sitting behind a "download" button, with an appropriate handler..before taking your browser to either that link as is or possibly some kind of session based link. Use an appropriate browser dev tool to see what is really going on on the download page.
    the hardest line to type correctly is: stty erase ^H
Re: download ZIP file from web
by leocharre (Priest) on May 27, 2010 at 14:13 UTC
    You gotta consider..

    a) are you trying to come up with a hack to be able to circumvent the mentioned problem (the site actaully points to some script or whatever that *afterwards* sends your browser the url to the file to download) in any given situation?

    Then maybe just download whatever you get to a temp file- checkout the mimetype, if it's html/etc, reap it for a .zip url.

    b) Or, are you trying to come up with a hack for this one site only?

    Consider unix wget or curl instead. Do this in bash.

Re: download ZIP file from web
by Anonymous Monk on Jun 14, 2010 at 17:40 UTC
    WWW::Mechanize may help too.