listanand has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I am using WWW::Mechanize to retrieve a certain number of webpages. However at some point during the process, the script abruptly dies.
Here's the relevant code:
my $mech = WWW::Mechanize->new();
$mech->timeout(100);
$mech->get($url); #Passed as argument to the method in which this snippet of code exists
warn $mech->response->status_line unless $mech->success;
The error message I get (before the script terminates) is: "Error GETing http://randomurl.com: Not Found at code.pl line 100"
where line 100 is $mech->get($url).
Any help is highly appreciated. Thank you very much.

Replies are listed 'Best First'.
Re: Perl Mechanize Woes
by almut (Canon) on Oct 15, 2009 at 17:36 UTC
    However at some point during the process, the script abruptly dies.

    You could try to unset autocheck in the constructor (and then handle errors yourself, of course):

    my $mech = WWW::Mechanize->new( autocheck => 0 ); ...

    When enabled (which is the default in newer1 versions of WWW::Mechanize), any errors make the program die.  You seem to have a newer version...

    ___

    1 from the Changes file:

    1.49_01 Sat Sep 27 23:50:04 CDT 2008 ======================================== [THINGS THAT MAY BREAK YOUR CODE] The autocheck argument to the constructor is now ON by default, unless WWW::Mechanize is being subclassed. There are so many new programmers whose ->get() calls fail unchecked that I'm now putting on the seat belts for them.
      This worked very nicely. Thank you very much for your timely help.
      Andy