I have a simple requirement of screen scraping a web-page and direct the HTML response to an output file. The URL will however redirect to an authentication (Login) page with form base authentication (no javascript) and upon authentication the report I am trying to view would show up. Interestingly, my code is working just fine in a Windows machine, however the same code below is not working in AIX machine and it looks like the click_button() function call does nothing. I have tried click(), submit(), but none is working so instead of getting the actual report all I get is the logon screen in the HTML output file. Any ideas, what can be wrong?

use WWW::Mechanize; use strict; my $username = "admin"; my $password = "welcome1"; my $outpath = "/home/data/output"; my $fromday = 7; my $url = "https://www.myreports.com/tax_report.php"; my $name = "tax_report"; my $outfile = "$outpath/$name.html"; my $mech = WWW::Mechanize->new(noproxy =>'0'); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); $year += 1900; $mon++; # since it will start from 0 $mday--; # yesterdays date (to day) $fromday = $mday - $days; #(from day) #Create URL extension for generating report with previous date my $dt_range = "?dc_range=Y&dc_date1=$mon%2F$fromday%2F$year&dc_date2= +$mon%2F$mday%2F$year"; my $url = $url . $dt_range; $mech->get($url); $mech->field(login => "$username"); $mech->field(passwd => "$password"); $mech->click_button(value=>"Login now"); my $response = $mech->content(); print "Generating report: $name...\n"; open (OUT, ">>$outfile")|| die "Cannot create report file $outfile"; print OUT "$response"; close OUT;

In reply to WWW::Mechanize click_button() not working in AIX by perl_monster

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.