use strict; use WWW::Mechanize; my $mech_cgi = WWW::Mechanize->new; my $mech_mod = WWW::Mechanize->new; $mech_cgi->get( 'http://www.foo.com/cgi/' ); $mech_mod->get( 'http://www.foo.com/modperl/' ); my @cgi_links = $mech_cgi->find_all_links( text_regex => qr/Example/ ) +; my @mod_links = $mech_mod->find_all_links( text_regex => qr/Example/ ) +; # test the first ten for( 0..9 ) { print "following link: ", $cgi_links[$_]->url, "\n"; $mech_cgi->follow_link( url => $cgi_links[$_]->url ) or die "Error following link ", $cgi_links[$_]->url; print "following link: ", $mod_links[$_]->url, "\n"; $mech_mod->follow_link( url => $mod_links[$_]->url ) or die "Error following link ", $mod_links[$_]->url; # do some stuff print "finished link $_\n"; }
Everything seems to go fine up to following the first link in the loop. (#0.) After that, when I attempt to follow the second link, my script dies with the error. Unfortunately I haven't yet figured out how to get a more useful error message from WWW::Mechanize. (I'm sure I'm missing something in the docs.)
Here is the output I get:
[mike@localhost ~]$ perl webdiff.pl following link /cgi-bin/m.cgi?mid=261847852 following link /perl/m?mid=261847852 finished link 0 Error following link /cgi-bin/m.cgi?mid=305436842 at webdiff.pl line 9 +1.
I appreciate any help. Thanks.
Update: Formatting error.
In reply to WWW::Mechanize and following multiple links by friedo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |