in reply to Mechanize clicking unnamed button

bcdeery,

Though it is considered (by some) rude to answer a question with another question, are you using WWW::Mechanize or Win32::IE::Mecahnize? The reason I ask is that click that button calls the JavaScript function goToPage, and WWW::Mechanize does not support JavaScript.

However to answer your question you can use the $mech->click_button method to click the nth button such as $mech->click_button(number=>3);. You may want to check out what the JavaScript does, it is perhaps possible to achieve what it is doing using Perl. Remember if in doubt read the documentation. Also, you have shown us the snippit of the HTML in question, but not your Perl code that is throwning the error.

Update: Slight change of formatting.

Hope this helps.

Martin

Replies are listed 'Best First'.
Re^2: Mechanize clicking unnamed button
by bcdeery (Novice) on Jul 13, 2006 at 16:18 UTC
    Update: I'm using WWW::Mechanize. Other than Java support, is there much difference in the two? Here is my code:
    #set initital webpage $url="http://www.fedex.com/ratefinder/home?cc=US&language=en&link=1&li +d=//Ship//Pack+Rates+Corp"; #open initial webpage my $mech = WWW::Mechanize->new(); $mech->get($url); while($line=<ZIPPAIRS>){ $indexForm2 = "standAloneActionForm"; $mech->form_name($indexForm2) ; chomp $line; ($Ozip, $Dzip)= split("\t",$line); print " $Dzip $Ozip\n"; #enter the zip codes and package weight of 3 lbs $mech->set_fields( origZip => $Ozip, destZip => $Dzip, totalPackageWeight =>"3", ); $mech->click_button(number=>3); #print current URL's html code to file 2 my $results_html = $mech->content; print OUTFILEB $results_html; die "All Done.\n";
    nothing prints to the file. I had $mech->click_button( value=>'Get Transit Time'); in where you had suggested to try using the button number. When I try the button number, I get an error "Can't call method "click" on an undefined value..... Sorry, I'm not very good with the boards. I have only used them a few times and haven't been on in over 6 months.
      bcdeery,

      I answered a similar question you asked a while back, explaining how to reverse engineer JavaScript. A quick look at the Win32::IE::Mechanize documentation will explain what the differences are between WWW::Mechanize and Win32::IE::Mechanize. Your post history seems to centre around the area of site scraping and processing. A quick look at your target site, in this case www.fedex.com suggests that you may want to check out Section 2. Use of fedex.com. from their Terms of service, which is something you may want to consider:

      "The use of automated dial-in or inquiry devices to obtain information through fedex.com is strictly prohibited."

      For this reason I won't be providing any more information over and above what has already been provided to you.

      Thanks

      Martin

        Good thing he used www.fedex.com and not fedex.com ;)

        (While the ToS doesn't cover www.fedex.com or the FedEx ship manager at www.fedex.com, using an automated agent to collect info from these violates the spirit of the ToS. Also, they can change the ToS at any time to fix this omission.)

        Hey Martin, I appreciate the help you've given me and REALLY appreciate pointing out the Terms of Service. I was not aware of this. I thought I had looked for a robots.txt in the past and found nothing the matter of scraping. I guess I will need to go a different route. Maybe I can convince my account rep to do something useful for a change. And I apologize for asking redundant questions, but this is the only place I have to learn other than the horrible book I picked up. This is only the third program I've tried writing. I'm not an expert---I'm not even a programmer.