in reply to Re: WWW::Mechanize problem
in thread WWW::Mechanize problem

OK, here is exactly what Im trying to do. Im trying to make the program ask the user for a zip code they want to do a search on to find all the nearest insurance agencies in the area. Here is the site I am trying to use http://www.unitrinspecialty.com/us/locator/. Here is the code so far..
use strict; use warnings; print "What zip code? \n"; my $module_name = <STDIN> or die "Must specify module name on command line"; use WWW::Mechanize; my $browser = WWW::Mechanize->new(); $browser->get("http://www.unitrinspecialty.com/us/locator/"); $browser->form_number(1); $browser->field("zipCode", $module_name); $browser->click();

Replies are listed 'Best First'.
Re^3: WWW::Mechanize problem
by jasonk (Parson) on May 29, 2008 at 02:31 UTC

    Go to the website in a browser. Select 'View Source'. Search for the word 'form'. Discover that form #1 is the search box in the upper right hand corner, and you are attempting to set non-existent fields in the wrong form.

    After that, either try $mech->form_number(2), or better yet $mech->form_name( 'zipForm' ) or even $mech->form_with_fields( 'zipCode' ).


    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!
      Awesome. Thanks man. Now I got this lol... Input 'zipCode' has maxlength '5' at C:/Perl/lib/WWW/Mechanize.pm line 1247 Here is the code:
      use strict; use warnings; print "What zip code? \n"; my $module_name = <STDIN> or die "Must specify module name on command line"; use WWW::Mechanize; my $browser = WWW::Mechanize->new(); $browser->get("http://www.unitrinspecialty.com/us/locator/"); $browser->form_name('zipForm'); $browser->field("zipCode", $module_name); $browser->click();
        "12345\n" is 6 characters. chomp

        You mentioned the command line in your error message. Perhaps you want to use @ARGV instead of <STDIN>?

        use strict; use warnings; use WWW::Mechanize qw( ); use File::Basename qw( basename ); sub usage { my $prog = basename($0); print STDERR ("usage: $prog {zipcode}\n"); exit(1); } my ($zip_code) = @ARGV; defined($zip_code) or usage(); my $browser = WWW::Mechanize->new(); $browser->get("http://www.unitrinspecialty.com/us/locator/"); $browser->form_name('zipForm'); $browser->field("zipCode", $module_name); $browser->click();