Getting WWW::Mechanize to submit a form

Getting WWW::Mechanize to submit a form

am 15.09.2007 21:44:30 von Amer Neely

Apologies if I upset someone by posting this here. I had no response in
comp.lang.perl.misc.

I'm trying to use this module to populate and submit a form on a remote
server, but *apparently* it is not doing either.

-------------------------- 8< ---------------------------
#! /usr/bin/perl
use strict;
use warnings;

use lib (
'/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib',
'/home/usr241/cgi-bin/PerlMods/libwww-perl-5.808/lib',
'/home/usr241/cgi-bin/PerlMods/HTML-Parser-3.56/lib/'
);
use WWW::Mechanize;
use HTML::Form;

my $mech = WWW::Mechanize->new();
my $url = "http://xxx.xxx.xxx./form.aspx"; # edited
my $name="form1";

$mech->get( $url );
die "Can't even get the home page: ", $mech->response->status_line
unless $mech->success;

print "Found $url
\n" if $mech->success();

$mech->form($name);

die "Can't get the form name: ", $mech->response->status_line
unless $mech->success;

print "Found '$name'
\n" if $mech->success();

$mech->field('txtFirstName',$Firstname); # previously defined
$mech->field('txtLastName',$Lastname); # previously defined

print "Populated '$name'
\n" if $mech->success();

my $results = $mech->submit();

print "Submitted '$name'
\n" if $mech->success();
print "\n";

-------------------------- 8< ---------------------------


When the script runs, it prints out everything as if there were no
errors. But the programmer running the form at the remote site is saying
nothing is coming through. I've tested a similar script myself, taking
form data from a static HTML form, and posting it to another static HTML
form on a different server, and it works fine.

Can anyone see anything wrong with this code that would cause it to
fail? The form I'm trying to populate and submit is a .aspx document.

--
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"

Re: Getting WWW::Mechanize to submit a form

am 16.09.2007 01:50:07 von paduille.4061.mumia.w+nospam

On 09/15/2007 02:44 PM, Amer Neely wrote:
> Apologies if I upset someone by posting this here. I had no response in
> comp.lang.perl.misc.
>
> I'm trying to use this module to populate and submit a form on a remote
> server, but *apparently* it is not doing either.
>
> -------------------------- 8< ---------------------------
> #! /usr/bin/perl
> use strict;
> use warnings;
>
> use lib (
> '/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib',
> '/home/usr241/cgi-bin/PerlMods/libwww-perl-5.808/lib',
> '/home/usr241/cgi-bin/PerlMods/HTML-Parser-3.56/lib/'
> );

If you use the INSTALLSITELIB parameter when building the modules, you
won't need to do this.

perl Makefile.PL PREFIX=/path/to/modules INSTALLSITELIB=/path/to/modules
INSTALLDIRS=site

(In your scripts just do this:)

use lib '/path/to/modules';

> use WWW::Mechanize;
> use HTML::Form;
>
> my $mech = WWW::Mechanize->new();
> my $url = "http://xxx.xxx.xxx./form.aspx"; # edited
> [...]
>
>
> Can anyone see anything wrong with this code that would cause it to
> fail? The form I'm trying to populate and submit is a .aspx document.
>

No, I can't see what's wrong because I can't see the HTML that creates
the form.

Maybe the HTML has javascript to initialize some parts of the form, and
the server rejects any forms that have not been so initialized.

Re: Getting WWW::Mechanize to submit a form

am 16.09.2007 16:35:30 von Amer Neely

Mumia W. wrote:
> On 09/15/2007 02:44 PM, Amer Neely wrote:
>> Apologies if I upset someone by posting this here. I had no response
>> in comp.lang.perl.misc.
>>
>> I'm trying to use this module to populate and submit a form on a
>> remote server, but *apparently* it is not doing either.
>>
>> -------------------------- 8< ---------------------------
>> #! /usr/bin/perl
>> use strict;
>> use warnings;
>>
>> use lib (
>> '/home/usr241/cgi-bin/PerlMods/WWW-Mechanize-1.18/lib',
>> '/home/usr241/cgi-bin/PerlMods/libwww-perl-5.808/lib',
>> '/home/usr241/cgi-bin/PerlMods/HTML-Parser-3.56/lib/'
>> );
>
> If you use the INSTALLSITELIB parameter when building the modules, you
> won't need to do this.
>
> perl Makefile.PL PREFIX=/path/to/modules INSTALLSITELIB=/path/to/modules
> INSTALLDIRS=site

Ah, thank you for that. I was already using PREFIX, but was unaware of
this one.

>
> (In your scripts just do this:)
>
> use lib '/path/to/modules';
>
>> use WWW::Mechanize;
>> use HTML::Form;
>>
>> my $mech = WWW::Mechanize->new();
>> my $url = "http://xxx.xxx.xxx./form.aspx"; # edited
>> [...]
>>
>>
>> Can anyone see anything wrong with this code that would cause it to
>> fail? The form I'm trying to populate and submit is a .aspx document.
>>
>
> No, I can't see what's wrong because I can't see the HTML that creates
> the form.
>
> Maybe the HTML has javascript to initialize some parts of the form, and
> the server rejects any forms that have not been so initialized.
>

The form I am trying to populate is made from an .aspx file, so I don't
really know what they are doing at their end. I'll suggest a different
approach to them. Thanks for responding.

--
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"

Re: Getting WWW::Mechanize to submit a form

am 16.09.2007 19:36:16 von paduille.4061.mumia.w+nospam

On 09/16/2007 09:35 AM, Amer Neely wrote:
> Mumia W. wrote:
>> [...]
>>
>> perl Makefile.PL PREFIX=/path/to/modules
>> INSTALLSITELIB=/path/to/modules INSTALLDIRS=site
>
> Ah, thank you for that. I was already using PREFIX, but was unaware of
> this one.
>

You're welcome. For more information read the docs for ExtUtils::MakeMaker:

Start->Run->"perldoc ExtUtils::MakeMaker"

The ActiveState help menus might also have them.

>> [...]
>> Maybe the HTML has javascript to initialize some parts of the form,
>> and the server rejects any forms that have not been so initialized.
>>
>
> The form I am trying to populate is made from an .aspx file, so I don't
> really know what they are doing at their end. I'll suggest a different
> approach to them. Thanks for responding.
>

Aspx programs produce HTML (AFAIK), so naturally you would take a look
at the HTML before attempting to write a Perl script to interact with
its forms.

Re: Getting WWW::Mechanize to submit a form

am 16.09.2007 22:02:58 von Amer Neely

Mumia W. wrote:
> On 09/16/2007 09:35 AM, Amer Neely wrote:
>> Mumia W. wrote:
>>> [...]
>>>
>>> perl Makefile.PL PREFIX=/path/to/modules
>>> INSTALLSITELIB=/path/to/modules INSTALLDIRS=site
>>
>> Ah, thank you for that. I was already using PREFIX, but was unaware of
>> this one.
>>
>
> You're welcome. For more information read the docs for ExtUtils::MakeMaker:
>
> Start->Run->"perldoc ExtUtils::MakeMaker"
>
> The ActiveState help menus might also have them.
>

Yep, was just going through them.

>>> [...]
>>> Maybe the HTML has javascript to initialize some parts of the form,
>>> and the server rejects any forms that have not been so initialized.
>>>
>>
>> The form I am trying to populate is made from an .aspx file, so I
>> don't really know what they are doing at their end. I'll suggest a
>> different approach to them. Thanks for responding.
>>
>
> Aspx programs produce HTML (AFAIK), so naturally you would take a look
> at the HTML before attempting to write a Perl script to interact with
> its forms.

I have the form name and field names etc. but for some reason the 'other
side' is saying nothing is getting posted to it. I'm very confident that
my script works - I've tested it myself filling in a plain HTML form,
which gets posted to my script, which then uses Mechanize to populate a
remote form successfully. So I'm not clear what is different about this
scenario. I've sent them a plain HTML form to host so I can point to
that. My thinking is that since their form points back to itself for
execution, this may affect things. Mechanize comes back with no errors
though, which is the confusing part.

--
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"

Re: Getting WWW::Mechanize to submit a form

am 17.09.2007 19:24:37 von Amer Neely

Mumia W. wrote:
> On 09/16/2007 09:35 AM, Amer Neely wrote:
>> Mumia W. wrote:
>>> [...]
>>>
>>> perl Makefile.PL PREFIX=/path/to/modules
>>> INSTALLSITELIB=/path/to/modules INSTALLDIRS=site
>>
>> Ah, thank you for that. I was already using PREFIX, but was unaware of
>> this one.
>>
>
> You're welcome. For more information read the docs for ExtUtils::MakeMaker:
>
> Start->Run->"perldoc ExtUtils::MakeMaker"
>
> The ActiveState help menus might also have them.
>
>>> [...]
>>> Maybe the HTML has javascript to initialize some parts of the form,
>>> and the server rejects any forms that have not been so initialized.
>>>
>>
>> The form I am trying to populate is made from an .aspx file, so I
>> don't really know what they are doing at their end. I'll suggest a
>> different approach to them. Thanks for responding.
>>
>
> Aspx programs produce HTML (AFAIK), so naturally you would take a look
> at the HTML before attempting to write a Perl script to interact with
> its forms.

The environment at the remote server is .NET. So far they have not been
able to get any data from my Mechanize script. I've set a user agent
that should be acceptable, but still no deal.

Does anyone here have any experience talking with .NET services?
Specifically getting WWW::Mechanize to submit a form on a .NET server?

--
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
"Others make web sites. We make web sites work!"