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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |