#!perl # Automated navigation through web pages use strict; use warnings; use WWW::Mechanize; my $testpage='https://www.openinvoice.com/docp/login/login.jsp'; my $teststring = 'Oilfield Commerce Platform (TM) Login'; $testpage = 'http://www.openinvoice.com'; $teststring = 'login now'; my $a = WWW::Mechanize->new(autocheck => 1, agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461)', keep_alive=> 1); $a->proxy(['http', 'https'], 'http://www-proxy:8080/proxy.pac'); my @silly_headers = ('Accept-Language' => 'en-us', 'Accept-Encoding' => 'gzip, deflate', 'Accept' => '*/*'); $a->get($testpage, @silly_headers); $a->success() or die "Failed to get $testpage: ".$a->status()."\n".$a->res()->as_string()."\n"; my $link = $a->find_link( text => 'login now.' ) or do { warn "Did not find link\n"; warn "Link: ". $_->[1] .' -> '. $_->[0] ."\n" for $a->links(); }; #use Data::Dumper; #die Dumper($link), "\n"; $a->get($link->[0], @silly_headers); $a->success() or warn "Followed link to ", $a->base, "\n"; $a->success() or die "Failed to get ".($a->base).': '.$a->res()->as_string()."\n"; print "Page is ", $a->content, "\n";