Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep WWW::Mechanize from following redirects?

I have a Perl script that uses WWW::Mechanize to read from a file and perform some automated tasks on a website. However, the website uses a 302 redirect after every time I request a certain page. I don't want to be redirected (the page that it redirects to takes too long to respond); I just want to loop through the file and call the first link over and over. I can't figure out how to make WWW::Mechanize NOT follow redirects. Any suggestions?

like image 201
rfusca Avatar asked May 21 '09 19:05

rfusca


2 Answers

WWW::Mechanize is a subclass of LWP::UserAgent. So you can use any LWP::UserAgent methods.

my $mech = WWW::Mechanize->new();
$mech->requests_redirectable([]);
like image 194
Alexandr Ciornii Avatar answered Oct 04 '22 03:10

Alexandr Ciornii


WWW::Mechanize is a subclass of LWP::UserAgent; you can set the max_redirect or requests_redirectable options in the constructor as you would with LWP::UserAgent.

like image 45
Wooble Avatar answered Oct 04 '22 03:10

Wooble