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

For some unknown reasons the site that I want to post isn't posted. But I dont figure out why. Thank you for any advice.
my $url = URI->new("http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi"); $mech->get($url); if($mech->success()) { $mech->form_number(1); $mech->set_fields( name => "$names[$num]", Sequence => "$lines[$num]", pffold => "pf", Params => "RNA", Temp => "37", email => 'KaiAllard@web.de' ); $mech->untick(toggles => "-4"); $mech->untick(toggles => "-d"); $mech->tick(toggles => "-noCloseGU"); $mech->tick(toggles => "-noLP"); $mech->untick(plot => "on"); $mech->untick(SVG => "on"); $mech->untick(SSview => "on"); $mech->click_button(value => "Fold it"); if($mech->success()) { ... do something
At this point I just get the original page but not the following page that I want to reach. I dont get any warning or something... But it seams that I dont post the page. There is only one case that the real page does return to its original: no "Sequence"...

Replies are listed 'Best First'.
Re: Mechanize Problems
by planetscape (Chancellor) on Dec 13, 2005 at 10:37 UTC

    My boilerplate advice is this:

    I would try using a module such as HTTP::Recorder or WWW::Mechanize::Shell to record a successful manual form submission. The output of HTTP::Recorder, for instance, can be "dropped" right into your WWW::Mechanize scripts.

    Another important tool for finding out what is really happening behind the scenes between server and browser is a protocol analyzer such as Ethereal.

    Don't forget that Super Search is your friend here on PM. Many questions such as yours have been asked recently...

    Good luck,

    planetscape
      Thank you. I tried Mech::Shell. A very nice tool. But unfortunately it generates the code I wrote (a bit different of course) with the same problem. Well never ind I have to accept that the site I want to reach must have a subtil bug.

        Some experimentation with HTTP::Recorder suggests that what you want in place of $mech->click_button(value => "Fold it"); is instead: $mech->click('Action'); :

        $agent->get('http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi'); $agent->form_number(1); $agent->tick('toggles', '-noLP'); $agent->field('name', 'fakename'); $agent->tick('SVG', 'on'); $agent->field('email', name@domain.com'); $agent->field('Temp', '37'); $agent->tick('plot', 'on'); $agent->field('Params', 'RNA'); $agent->field('Sequence', 'GATTACAGATTACAGATTACA'); $agent->field('pffold', 'pf'); $agent->click('Action');

        (HTTP::Recorder records scripts using "$agent" instead of "$mech".)

        Viewing the HTML source of the page in question would have revealed your error:

        <input type="hidden" name="rec-form1-submit-Action" value=1> <input type="submit" name="Action" value="Fold it"> ^^^^^^

        HTH,

        planetscape
Re: Mechanize Problems
by gu (Beadle) on Dec 12, 2005 at 18:51 UTC
    As mech-dump indicates that the button you are clicking is the submit button, instead of clicking the button I would use the submit function from WWW::Mechanize, as follows :

    ... $mech->untick(SSview => "on"); $mech->submit; die $mech->res->status_line unless $mech->success ; my $uri = $mech->response->request->uri->as_string ; print $uri ;
    Is it better ?

    We discussed form submitting in how to submit html form?.

    Hope this helps.

    Gu
      Thank you for your effort... but it was my first thought. No sorry there is no improvement... For some reason the post is a kind of success but just returns to the original page, no matter if submit or button, or if I do some hardcoding... always the same result. I am lost.