From WWW::Mechanize:
autocheck => [0|1]Here, errors means die(). Since your program used autocheck=>1 by default, it dies when a problem occurs while calling $mech_cgi->follow_link(...). It has no chance to reach your own call to die - which is not what you want - as already observed by roboticus (Updated: paragraph).
Checks each request made to see if it was successful. This saves you the trouble of manually checking yourself. Any errors found are errors, not warnings.
The default value is ON, unless it's being subclassed, in which case it is OFF. This means that standalone WWW::Mechanizeinstances have autocheck turned on, which is protective for the vast majority of Mech users who don't bother checking the return value of get() and post() and can't figure why their code fails. However, if WWW::Mechanize is subclassed, such as for Test::WWW::Mechanize or Test::WWW::Mechanize::Catalyst, this may not be an appropriate default, so it's off.
Now you have at least two options:
Example (2nd alternative):
use strict; use WWW::Mechanize; use Storable; my $mech_cgi = WWW::Mechanize->new( autocheck => 0 ); $mech_cgi->get( 'http://www.molmovdb.org/cgi-bin/browse.cgi' ); my @cgi_links = $mech_cgi->find_all_links( url_regex => qr/motion.cgi/ + ); for my $link ( @cgi_links ) { # no C-style loop... print "following link: ", $link->url, "\n"; my $res = $mech_cgi->follow_link( url => $link->url ); # $res is a HTTP::Response object if ( $res->is_success ) { print "OK : Processing result ...\n"; } else { print "ERR: Failed to retrieve page: ", $res->status_line, "\n"; } $mech_cgi->back; sleep 5; # anti-aggressive scraping }
Result:
... following link: http://www.molmovdb.org/cgi-bin/motion.cgi?ID=ntrc OK : Processing result ... following link: http://www.molmovdb.org/cgi-bin/motion.cgi?ID=ppar ERR: Failed to retrieve page: 500 Internal Server Error following link: http://www.molmovdb.org/cgi-bin/motion.cgi?ID=rhorbp OK : Processing result ... ...
Please check also if you have permission to scrape this site.
In reply to Re: conditional testing for error 500 webpages before following them?
by Perlbotics
in thread conditional testing for error 500 webpages before following them?
by fraizerangus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |