Help with file download.

Discussion in 'Perl Misc' started by Jim Simpson, Jul 2, 2004.

  1. Jim Simpson

    Jim Simpson Guest

    My bank allows me to download a .csv file of my account and I'm trying to
    automate the process. So far I've gotten into the download manager sheet but
    after hours and hours of work I've been unable to get any further. The
    download manager sheet contains 2 forms plus a "download Button" - one form
    is a 1 of 2 choice drop down menu the other is a 1 of 10 choice radio button
    form. Can someone please help me. A portion of my code follows:
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # secure login
    my $ua = LWP::UserAgent->new();
    $ua->protocols_allowed( ['https'] );
    $ua->cookie_jar(HTTP::Cookies->new(file => ".cookies.txt", autosave =>
    1));
    my $response = $ua->post($https_login, [ 'username' => "$https_user",
    'password' => "$https_pass", 'submit' => 'Submit' ] );
    if ($response->is_error())
    {
    printf " %s\n", $response->status_line;
    print "https request error!\n";
    }
    else
    {
    open my $fh, '> myfile.html' or die $!;
    print $fh $response -> content;
    close $fh;
    }

    # get download manager sheet.
    if ($response->content() =~ (/.*<a\s+href="(.*)">Account\s+Download/))
    {
    my $nav_url = $baseurl . $1;
    my $response2 = $ua->post($nav_url);
    if ($response2->is_error())
    {
    printf " %s\n", $response2->status_line;
    print "https request error!\n";
    }
    else
    {
    open my $fh, '> myfile2.html' or die $!;
    print $fh $response2 -> content;
    close $fh;
    }
    }
    else
    {
    printf " %s\n", $response->status_line;
    print "https request error!\n";
    }

    # Get "download.csv".
    my $csvresponse = $ua->post($burl . $1, [ 'name' => "name of dropdown
    form", 'VALUE' => "$https_value2", 'NAME' => 'name of Radio button form',
    'VALUE' => "$https_value1", 'name' => "name of button", 'value' =>
    "Download Data"] );

    if ($csvresponse->is_error())
    {
    printf " %s\n", $csvresponse->status_line;
    print "https request error!\n";
    }
    else
    {
    open my $fh, '> myfile3.html' or die $!;
    print $fh $csvresponse -> content;
    close $fh;
    }
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    After running the above, my file2.html and myfile3.html both show the
    download manager sheet. I hope I have included enough info. If not I will be
    happy to provide more detail.

    Thanks for all help.

    Jim
     
    Jim Simpson, Jul 2, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Taylor
    Replies:
    2
    Views:
    1,028
    Ryan Taylor
    Nov 10, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,671
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  3. Sam --
    Replies:
    2
    Views:
    670
    Sam --
    Mar 17, 2005
  4. Rafal Majda
    Replies:
    5
    Views:
    2,469
    Rafal Majda
    Apr 18, 2005
  5. Brett  Kelly
    Replies:
    1
    Views:
    728
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
Loading...

Share This Page