#!c:\perl\bin -w use strict; use warnings; use LWP 5.8; my $browser = LWP::UserAgent->new; $browser->timeout(60); push @{ $browser->requests_redirectable }, 'POST'; my $cityInfoMainPageURL = 'http://www.ihoz.com/ilist.html'; my $distanceFinderURL = 'http://www.randmcnally.com/rmc/directions/dirGetMileageInput.jsp'; my $cities = $browser->get($cityInfoMainPageURL); my $distIn = $browser->get($distanceFinderURL); die ("Can't get $cityInfoMainPageURL -- ", $cities->status_line) unless $cities->is_success; die ("Can't get $distanceFinderURL -- ", $distIn->status_line) unless $distIn->is_success; print ($distIn->base, "\n"); print ($cities->base, "\n"); my $strtCity = 'Miami'; my $strtState = 'FL'; my $destCity = 'Albany'; my $destState = 'NY'; my $cityResponse = $browser->post ( $distanceFinderURL, [ 'txtStartCity' => $strtCity, 'txtStartState' => $strtState, 'txtDestCity' => $destCity, 'txtDestState' => $destState, ] ); die ("error submiting form") unless $cityResponse->is_success; print ($cityResponse->status_line, "\n"); print ($cityResponse->base, "\n"); $cityResponse->content =~ /Driving Distance:.*([1-9][0-9]*|0) miles/; print (1); # this used to be "print ($1)" but the warning # about the undefined variable was annoying #### http://www.randmcnally.com/rmc/directions/dirGetMileageInput.jsp http://www.ihoz.com/ilist.html 200 OK http://www.randmcnally.com/rmc/directions/dirGetMileageInput.jsp 1 #### http://www.altavista.com/ Couldn't find the match-string in the response #### use strict; use warnings; use LWP 5.64; my $browser = LWP::UserAgent->new; push @{ $browser->requests_redirectable }, 'POST'; my $word = 'tarragon'; my $url = 'http://www.altavista.com/'; my $response = $browser->post( $url, [ 'q' => $word, # the Altavista query string # 'pg' => 'q', 'avkw' => 'tgz', 'kl' => 'XX', ] ); die "$url error!!: ", $response->status_line unless $response->is_success; die "Weird content type at $url -- ", $response->content_type unless $response->content_type eq 'text/html'; print ($response->base . "\n"); if( $response->content =~ m{(AltaVista|Alta Vista).* .*found.* .*([0-9,]+).* .*results} ) { # The substring will be like "AltaVista found 2,345 results" print "$word: $2\n"; } else { print "Couldn't find the match-string in the response\n"; }