in reply to Re^2: mech follow_link question
in thread mech follow_link question
There are two things at play:
First Link not found at c:\websites\bla_bla\my_perl_script.pl is just the error message by Perl, which tells you the line number where the error was raised. You left off the line number, but it is likely the number of the line in the subroutine follow().
The second thing is, WWW::Mechanize behaves like a browser. If you issue ->follow_link for one link, all other links you may have collected will likely be not valid anymore, as they are not on the other page. Consider dumping the ->content for each page. Maybe you want to go ->back after visiting every page in turn?
As a last point, your style of using the &follow; syntax mixed with global variables is discomforting. I would rewrite that snippet as:
for my $link ( @links ) { follow( $link ); }; sub follow { my ($link) = @_; warn "Following contact link; if ($m->follow_link( url_regex => qr/contact/i)){ print $link->url."\n"; } };
As for your thoughts about how WWW::Mechanize works, and what the subroutines return, please read WWW::Mechanize. Most things are fatal to make it easier for you to spot when your assumptions deviate from the reality of the website you're automating.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: mech follow_link question
by zingbust (Initiate) on Feb 29, 2012 at 17:51 UTC | |
by Corion (Patriarch) on Feb 29, 2012 at 19:11 UTC |