www::Mechanize - problems finding forms

www::Mechanize - problems finding forms

am 22.06.2007 09:28:26 von hyle

Hi,

Perhaps somebody has an idea how to solve this problem, if its solveable.

I get sometimes this message, after i am running my script:

# There is no form numbered 1 at SwissModel.pm line 26
# Died at /usr/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1614, line 1620.

The part of the code where the error occours. (if complete code is needed just ask for it)

########
my $mech = WWW::Mechanize->new;
$mech->get('http://swissmodel.expasy.org/workspace/index.php ?func=modelling_simple1&userid=USERID&token=TOKEN');

$mech->submit_form
(
form_number => '1',
fields =>
{
sequence => $seq,
group => $temp
}
));
#########

I have 3 subs in this way, which are executed one after the other.
The program dies always on an other sub, which are connecting to different pages. once my list was executed completely, but often it do not finish the list.


best regards
Hüseyin
--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

Re: www::Mechanize - problems finding forms

am 22.06.2007 16:28:28 von peter.stevens

Hi,

[forgot to post this to the list ]

Does the compete code have any error checking? Web servers are far from
perfect beasts. Sometimes they don't respond, sometimes they don't send
the content you expect. So if you are striving for reliability, you need to

1. Verify that the HTTP transaction worked
2. Verity that the HTML text returned is (more or less) what you
expected.

(1) is easy - after mech->get, check the mech->status. (2) is harder.
checking for a string which is likely to appear (only) if you got what
you were looking for is an approach I have used with success.

If you don't get what you expect, error messages (or for patch
processing, mail yourself the results). mech->save_content is useful here.

So I would call mech->form, check for success, save the content if it
doesn't find the form, otherwise fill out the form and submit it....

Hope this helps,

Peter


hyle@gmx.at wrote:
> Hi,
>
> Perhaps somebody has an idea how to solve this problem, if its solveable.
>
> I get sometimes this message, after i am running my script:
>
> # There is no form numbered 1 at SwissModel.pm line 26
> # Died at /usr/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1614, line 1620.
>
> The part of the code where the error occours. (if complete code is needed just ask for it)
>
> ########
> my $mech = WWW::Mechanize->new;
> $mech->get('http://swissmodel.expasy.org/workspace/index.php ?func=modelling_simple1&userid=USERID&token=TOKEN');
>
> $mech->submit_form
> (
> form_number => '1',
> fields =>
> {
> sequence => $seq,
> group => $temp
> }
> ));
> #########
>
> I have 3 subs in this way, which are executed one after the other.
> The program dies always on an other sub, which are connecting to different pages. once my list was executed completely, but often it do not finish the list.
>
>
> best regards
> Hüseyin
>

Re: www::Mechanize - problems finding forms

am 22.06.2007 16:36:18 von peter.stevens

Hi,

Looks like you're moving in the right direction. BTW - forgot to mention
that mech->success is easier than checking the HTTP status code.

Checking mech->content against a regular expression is good (IMHO) and
the one you've got is probably a good start. The proof of the pudding
however is in the eating, so you will have to see if "action.php" is a
good (enough) criteria to determine that you have gotten the content you
expect.

BTW - the save content will only work if the directory Results/$id
already exists

Cheers,

Peter

Hüseyin KÖK wrote:
> hi,
>
> No i do not used error checking yet( im new in coding :))
> I also never thougt about that, because it worked weeks ago fine.
>
>
> now i just changed the code:
>
> so now i am parsing after mech->get if the form is there. This is the 2. advise you gave. do you think this works?
>
> ######
> my $mech = WWW::Mechanize->new;
> $mech->get('http://swissmodel.expasy.org/workspace/index.php ?func=modelling_simple1&userid=USERID&token=TOKEN');
>
> if($mech->content =~/form action=index.php/){ # look if form exists/available
> #print "Swissmodel Form - OK\n";
>
> $mech->submit_form # fill in form and submit
> (
> form_number => '1',
> fields =>
> {
> sequence => $seq,
> group => $temp
> }
> );
> }
> else{
> #print "Problem getting Form!\n";
>
> $mech->save_content("Results/$id/smerr.html");
> return 0;
> }
> #####
>
> at first i did not exactly figured put what mech->status returns, till i found out that this is standardized http response code.
> so if its 200 its ok, else there could be a problem. therefor i had to study the response codes. so i will insert this also.
>
> thanks for ur help and advise.
>
>
> best regards
> Hüseyin
>
>
>
>
>
>
>