friedo has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WWW::Mechanize and following multiple links
by Limbic~Region (Chancellor) on Nov 24, 2004 at 15:24 UTC | |
by friedo (Prior) on Nov 24, 2004 at 15:37 UTC | |
|
Re: WWW::Mechanize and following multiple links ( use WWW::Mechanize::Clones)
by diotalevi (Canon) on Nov 24, 2004 at 17:17 UTC | |
|
Re: WWW::Mechanize and following multiple links
by petdance (Parson) on Nov 24, 2004 at 21:12 UTC | |
by bart (Canon) on Nov 25, 2004 at 01:26 UTC | |
by Limbic~Region (Chancellor) on Nov 25, 2004 at 01:26 UTC | |
by ysth (Canon) on Nov 25, 2004 at 02:08 UTC | |
by diotalevi (Canon) on Nov 25, 2004 at 02:33 UTC | |
by petdance (Parson) on Nov 26, 2004 at 05:45 UTC |