Program Requirements
General:
After logging into a web site and traversing a few links,
I need to download a file.
Issue:
Manually, when I get to the file/link and the file/link
is chosen, an 'open-save-cancel' window appears to
which I choose the 'save' button. This is my dilemma
I think. In my program, I get to this last step and
my code does not get the file that the URL points to.

What could I be doing wrong? I get the 'file found'
but no file is downloaded.

Code is as follows:
#!/usr/bin/perl -w use strict; use WWW::Mechanize; use HTTP::Cookies; #use LWP::Debug qw(+); my $url = "https://home.host.net/"; my $username = "myuser"; my $password = "mypassword"; my $mech = WWW::Mechanize->new(); # # Get URL and login # $mech->cookie_jar(HTTP::Cookies->new()); $mech->get($url); $mech->form_name('Form1'); $mech->field("txtUsername", $username); $mech->field("txtPassword", $password); $mech->click(); my $url2 = "https://home.myhost.net/test/Reports/Users/FileToDownload. +zip"; my $tempfile = "C:/MyLocalFile.zip"; my $contents = $mech->get($url2, ':content_file' => $tempfile ); print "link found\n" if defined $contents;

Cheers (most humbly)

In reply to download a file from a web page by tony1234567893

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.