#!/usr/local/bin/perl require WWW::Mechanize; use strict; use warnings; { my $mech = WWW::Mechanize->new(); my $Input = ("LastName, FirstName"); &Search; sub Search { #print "Enter Search String:"; #goes to main search page. $mech->get('mywebsite.com/search.asp'); print "Webpage navigation start success result: "; &Get_Success; #submits the search form on the webpage just entered. $mech->submit_form( form_number => 1, fields => { query => $Input, } ); print "Form submission success result: "; &Get_Success; #finds all the links with "Server-" found inside the title. my @temp1 = $mech->find_all_links( text_regex => qr/Server-/i ); print "Link retrieval success result: "; &Get_Success; foreach (@temp1) { print $_->url(), "\n"; print $_->text(), "\n"; print $_->name(), "\n"; print $_->tag(), "\n"; } sub Get_Success { #prints the success result and starts a new line. print $mech->success(); print "\n"; } } #### sub Main { my $mech = ...; ...; Get_Success( $mech ); ...; } sub Get_Success { my( $mech ) = @_; #prints the success result and starts a new line. print $mech->success(); print "\n"; } #### #!/usr/local/bin/perl -- use strict; use warnings; use WWW::Mechanize 1.72; Main( @ARGV ); exit( 0 ); sub Main { my $search = shift; my $mech = WWW::Mechanize->new( qw/ autocheck 1 show_progress 1 /); $mech->get( $search ); my @serverLinks = $mech->find_all_links( url_regex => qr/_css/i ); for my $link( @serverLinks ) { for my $member ( qw/ url text name tag / ){ no warnings 'uninitialized'; print $link->$member, "\n" ; } } } __END__ $ perl dumplinks http://nowhere.example.com ** GET http://nowhere.example.com ==> 500 Can't connect to nowhere.example.com:80 (Bad hostname) (1s) Error GETing http://nowhere.example.com: Can't connect to nowhere.example.com:80 (Bad hostname) at dumplinks line 15. $ perl dumplinks http://example.com ** GET http://example.com ==> 302 Found ** GET http://www.iana.org/domains/example/ ==> 200 OK /_css/2008.1/reset-fonts-grids.css link /_css/2008.1/screen.css link /_css/2008.1/print.css link