- TO DO
- SEE ALSO
- COPYRIGHT & LICENSE
WWW::Mechanize::Plugin::FollowMetaRedirect - Follows 'meta refresh' link
use WWW::Mechanize; use WWW::Mechanize::Plugin::FollowMetaRedirect; my $mech = WWW::Mechanize->new; $mech->get( $url ); $mech->follow_meta_redirect; # we don't want to emulate waiting time $mech->follow_meta_redirect( ignore_wait => 1 ); # compatible for W::M::Pluggable use WWW::Mechanize::Pluggable; my $mech = WWW::Mechanize::Pluggable->new; ...
WWW::Mechanize doesn't follow so-called 'meta refresh' link. This module helps you to find the link and follow it easily.
If $mech->content() has a 'meta refresh' element like this,
<head> <meta http-equiv="Refresh" content="5; URL=/docs/hello.html" /> </head>
the code below will try to find and follow the link described as url=.
In this case, the above code is entirely equivalent to:
sleep 5; $mech->get("/docs/hello.html");
When a refresh link was found and successfully followed, HTTP::Response object will be returned (see WWW::Mechanize::get() ), otherwise nothing returned.
To sleep specified seconds is default if 'waiting second' was set. You can omit the meddling function by passing ignore_wait true.
$mech->follow_meta_redirect( ignore_wait => 1 );
Despite there was no efficient links on the document after issuing follow_meta_redirect(), $mech->is_success will still return true because the method did really nothing, and the former page would be loaded correctly (or why you proceed to follow?).
Only the first link will be picked up when HTML document has more than one 'meta refresh' links (but I think it should be so).
A bit more efficient optimization to suppress extra parsing by limiting job range within <head></head> region.
To implement auto follow feature (like $mech->auto_follow_meta_redirect(1) ) using W::M::Pluggable::post_hook() to W::M::get().
Ryo Okamoto <firstname.lastname@example.org>
Copyright (c) Ryo Okamoto, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.