So I am using WWW::Mechanize
to crawl sites. It works great, except if I request a url such as:
http://www.levi.com/
I am redirected to:
http://us.levi.com/home/index.jsp
And for my script I need to know that this redirect took place and what the url I was redirected to is. Is there anyway to detect this with WWW::Mechanize
or LWP
and then get the redirected url? Thanks!
If the status code is 3XX, then you should check response headers for redirection url.
You can also get to the same place by inspecting the
redirects()
method on the response object.Prints:
See https://metacpan.org/pod/HTTP::Response#$r-%3Eredirects Keep in mind that more than one redirect may have taken you to your current location. So you may want to inspect every response which is returned via
redirects()
.