Reputation: 41
I am using Perl with the WWW::Mechanize
module to submit a form to a webpage and save the result to a file. I know how to submit forms and save the data, but I can't save data after this six-second redirection.
After the form is submitted, the page is redirected to a page that says
Results should appear in this window in approximately 6 seconds...
and it is redirected again to the page with the result I want. My script can follow the first redirection, but not the second, and there is no link says something like "click here if not redirected".
Here is my script
use WWW::Mechanize;
my $mech = WWW::Mechanize->new(autocheck => 1);
$mech->get( "http://tempest.wellesley.edu/~btjaden/TargetRNA2/index.html");
$result = $mech->submit_form(
form_number => 1,
fields => {
text => 'Escherichia coli str. K-12 substr. MG1655',
sequence => '>RyhB' . "\n" .
'GCGATCAGGAAGACCCTCGCGGAGAACCTGAAAGCACGACATTGCTCACATTGCTTCCAGTATTACTTAGCCAGCCGGGTGCTGGCTTTT',
}
);
$mech->save_content(result);
Upvotes: 4
Views: 219
Reputation: 10903
Does the "6 seconds" contain something line the line below? [You may use save_content
method of WWW::Machenize to save page to file]
<meta http-equiv="refresh" content="5; url=http://example.com/">
YES=>
Take a look at sources of WWW::Mechanize::Plugin::FollowMetaRedirect.
It shows how WWW::Mechanize may follow meta refresh with redirect.
It may quite likely solve your problem.
Upvotes: 0
Reputation: 1818
What you need to do is extract the redirect URL and ran it manually:
Try this:
use WWW::Mechanize;
my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->get( "http://tempest.wellesley.edu/~btjaden/TargetRNA2/index.html");
$result = $mech->submit_form(
form_number => 1,
fields =>
{
text => 'Escherichia coli str. K-12 substr. MG1655',
sequence => '>RyhB GCGATCAGGAAGACCCTCGCGGAGAACCTGAAAGCACGACATTGCTCACATTGCTTCCAGTATTACTTAGCCAGCCGGGTGCTGGCTTTT',
}
);
my $content = $mech->content;
my $url1 = 'http://tempest.wellesley.edu/~btjaden/cgi-bin/';
my ($url2) = $content =~ /URL=(targetRNA2\.cgi?.+)?">/;
$mech->get($url1.$url2);
$mech->save_content(result);
Upvotes: 3