First Mech script: entering a form value (another simple thing no doubt)

2013-03-14 Thread G M

Hi all,

I managed to get the problem with my script not connecting to the page last 
night, turned out my web host wouldn't allow it.  Got that sorted.  Filling in 
the form should be really simple but I'm getting the following error when 
trying to set the "acOriginAirport" field, I thought it might be to do with the 
javascript on the page but I'm entering a value that the form accepts.

The form is being found on the page as I can dump out $agent->forms();

Any ideas anyone?

Status: 500
Content-type: text/html

Software error:
Can't call method "value" on an undefined value at 
/usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1407.


This is my script:
#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use WWW::Mechanize;
use HTML::TokeParser;
use Data::Dumper;
print "Content-type: text/html\n\n";
print "setting up mech";
my $agent = WWW::Mechanize->new();
   $agent->agent_alias('Windows Mozilla');
print "mech setup";
   
$agent->get('http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279');
print "setting up airports ";
$agent->field("acOriginAirport", "Glasgow GLA");




Cheers in advance,

G :)
  

Re: First Mech script: entering a form value (another simple thing no doubt)

2013-03-14 Thread Jim Gibson

On Mar 14, 2013, at 8:27 AM, G M wrote:

> 
> Hi all,
> 
> I managed to get the problem with my script not connecting to the page last 
> night, turned out my web host wouldn't allow it.  Got that sorted.  Filling 
> in the form should be really simple but I'm getting the following error when 
> trying to set the "acOriginAirport" field, I thought it might be to do with 
> the javascript on the page but I'm entering a value that the form accepts.
> 
> The form is being found on the page as I can dump out $agent->forms();
> 
> Any ideas anyone?
> 
> Status: 500
> Content-type: text/html
> 
> Software error:
> Can't call method "value" on an undefined value at 
> /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1407.
> 
> 
> This is my script:
> #!/usr/bin/perl -w
> 
> use strict;
> use CGI qw(:standard);
> use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
> use WWW::Mechanize;
> use HTML::TokeParser;
> use Data::Dumper;
> print "Content-type: text/html\n\n";
> print "setting up mech";
> my $agent = WWW::Mechanize->new();
>   $agent->agent_alias('Windows Mozilla');
> print "mech setup";
>   
> $agent->get('http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279');
> print "setting up airports ";
> $agent->field("acOriginAirport", "Glasgow GLA");

I have not used WWW::Mechanize, but from reading the documentation, it would 
seem you must call $agent->form_number($number) with a form number before 
making any calls to field().

Line 1407 of Mechanize.pm is part of the field method:

sub field {
my ($self, $name, $value, $number) = @_;
$number ||= 1;

my $form = $self->current_form();
if ($number > 1) {
$form->find_input($name, undef, $number)->value($value);
}
else {
if ( ref($value) eq 'ARRAY' ) {
$form->param($name, $value);
}
else {
$form->value($name => $value);  # line 1407
}
}
}

The current_form() method is returning null because you have not specified 
(with a call to form_number()) which form you are using. Hence the error 
message you are seeing.




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: First Mech script: entering a form value (another simple thing no doubt)

2013-03-14 Thread G M

Hi,

Thanks for replying.  As far as I understand it will return undef if no form is 
found.  The form is there so it should do something I would've though, I tried 
adding in that line anyway using 1 to signify the first (and only) form on the 
page, still get the same error though :(


Cheers,

G :)


> Subject: Re: First Mech script: entering a form value (another simple thing 
> no doubt)
> From: jimsgib...@gmail.com
> Date: Thu, 14 Mar 2013 09:27:27 -0700
> To: beginners@perl.org
> 
> 
> On Mar 14, 2013, at 8:27 AM, G M wrote:
> 
> > 
> > Hi all,
> > 
> > I managed to get the problem with my script not connecting to the page last 
> > night, turned out my web host wouldn't allow it.  Got that sorted.  Filling 
> > in the form should be really simple but I'm getting the following error 
> > when trying to set the "acOriginAirport" field, I thought it might be to do 
> > with the javascript on the page but I'm entering a value that the form 
> > accepts.
> > 
> > The form is being found on the page as I can dump out $agent->forms();
> > 
> > Any ideas anyone?
> > 
> > Status: 500
> > Content-type: text/html
> > 
> > Software error:
> > Can't call method "value" on an undefined value at 
> > /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1407.
> > 
> > 
> > This is my script:
> > #!/usr/bin/perl -w
> > 
> > use strict;
> > use CGI qw(:standard);
> > use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
> > use WWW::Mechanize;
> > use HTML::TokeParser;
> > use Data::Dumper;
> > print "Content-type: text/html\n\n";
> > print "setting up mech";
> > my $agent = WWW::Mechanize->new();
> >   $agent->agent_alias('Windows Mozilla');
> > print "mech setup";
> >   
> > $agent->get('http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279');
> > print "setting up airports ";
> > $agent->field("acOriginAirport", "Glasgow GLA");
> 
> I have not used WWW::Mechanize, but from reading the documentation, it would 
> seem you must call $agent->form_number($number) with a form number before 
> making any calls to field().
> 
> Line 1407 of Mechanize.pm is part of the field method:
> 
> sub field {
> my ($self, $name, $value, $number) = @_;
> $number ||= 1;
> 
> my $form = $self->current_form();
> if ($number > 1) {
> $form->find_input($name, undef, $number)->value($value);
> }
> else {
> if ( ref($value) eq 'ARRAY' ) {
> $form->param($name, $value);
> }
> else {
> $form->value($name => $value);  # line 1407
> }
> }
> }
> 
> The current_form() method is returning null because you have not specified 
> (with a call to form_number()) which form you are using. Hence the error 
> message you are seeing.
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
  

Re: First Mech script: entering a form value (another simple thing no doubt)

2013-03-14 Thread David Precious
On Thu, 14 Mar 2013 16:42:52 +
G M  wrote:

> 
> Hi,
> 
> Thanks for replying.  As far as I understand it will return undef if
> no form is found.  The form is there so it should do something I
> would've though, I tried adding in that line anyway using 1 to
> signify the first (and only) form on the page, still get the same
> error though :(

There are no forms on the page.

  DB<6> $mech = WWW::Mechanize->new;
  DB<7> $mech->get(
'http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279');
  DB<8> x $mech->forms;
  empty array

See also:

[davidp@supernova:~]$ wget -q -O-
http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279 |
grep -i 'http://www.easyjet.com/EN/Booking.mvc, so
take the field names from the source of the URL you gave before, and
POST them at that URL, and see what happens.

Failing that, you'll have to use the form in your browser while using
an addon like Firebug or something, or capturing HTTP traffic off the
wire, and see what happens, and make your script do the same.



-- 
David Precious ("bigpresh") 
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: First Mech script: entering a form value (another simple thing no doubt)

2013-03-14 Thread G M

Hi,

Thanks for that, yeah I can see there are no  tags on that page, I'll 
give your suggestion a go.  Thank you very much!


G :)

> Date: Thu, 14 Mar 2013 16:56:37 +
> From: dav...@preshweb.co.uk
> To: beginners@perl.org
> Subject: Re: First Mech script: entering a form value (another simple thing 
> no doubt)
> 
> On Thu, 14 Mar 2013 16:42:52 +
> G M  wrote:
> 
> > 
> > Hi,
> > 
> > Thanks for replying.  As far as I understand it will return undef if
> > no form is found.  The form is there so it should do something I
> > would've though, I tried adding in that line anyway using 1 to
> > signify the first (and only) form on the page, still get the same
> > error though :(
> 
> There are no forms on the page.
> 
>   DB<6> $mech = WWW::Mechanize->new;
>   DB<7> $mech->get(
> 'http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279');
>   DB<8> x $mech->forms;
>   empty array
> 
> See also:
> 
> [davidp@supernova:~]$ wget -q -O-
> http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279 |
> grep -i ' [davidp@supernova:~]$
> 
> WWW::Mechanize wants to be able to find a form to actually submit.
> 
> You may be able to just fake the request yourself - at a quick glance,
> it looks like it submits to http://www.easyjet.com/EN/Booking.mvc, so
> take the field names from the source of the URL you gave before, and
> POST them at that URL, and see what happens.
> 
> Failing that, you'll have to use the form in your browser while using
> an addon like Firebug or something, or capturing HTTP traffic off the
> wire, and see what happens, and make your script do the same.
> 
> 
> 
> -- 
> David Precious ("bigpresh") 
> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
> www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
> www.preshweb.co.uk/cpanwww.preshweb.co.uk/github
> 
> 
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
>