August 6th, 2012, 12:22 AM
WWW::Mechanize returning errors
I am trying to use WWW::Mechanize in a simple script and it all ways comes up with an error.
the error is
$url = 'http://www.google.com';
$m->field('q', 'test search');
$response = $m->submit();
Can't call method "get" on an undefined value at /home/Documents/spider/spider1/mainspider3.pl line 4.
August 6th, 2012, 03:13 AM
What is $m?
You are hoping it is a WWW::Mechanize object, since you call Mechanize methods on it, but you never defined or instantiated it.
The essential, and missing line would be:
my $m = WWW::Mechanize->new;
August 9th, 2012, 06:42 AM
hi guys, im trying to use WWW::Mechanize. Can you please tell me how can i know which form_name("????") and which field('????', 'test search') should i put. Where can i find those variables?
August 9th, 2012, 02:48 PM
I was wondering the same.
August 9th, 2012, 04:15 PM
The information is in the HTML source. Just about all browsers allow you to view the source (might be on a developer menu). If not that, then download the page and open it in a text editor.
Originally Posted by andreas.london
If you look at the source for this page for example, you'll find several forms. Some have names, some have ids, some have neither.
If you look at the WWW::Mechanize methods, you'll see these for selecting forms:
Get all the forms
$mech->form_name( $name )
$mech->form_id( $name )
$mech->form_with_fields( @fields )
Get a form by number
Get a form by name
Get a form by id
Get a form by matching available field names
That's just to give you the flexibility of finding forms in many different ways. If you know you want the first or second form on the page, you can get it by number. If it has a name, use that. If it has an id, use that.
August 10th, 2012, 05:02 AM
I see. yea, i found the form names and ids!
Unfortunately i still have an error when im using this code:
my $mech = WWW::Mechanize->new;
$url = 'https://demo01.service-now.com/navpage.do';
$number = 1;
Thanks a lot.
Can't call method "value" on an undefined value at C:/Perl/lib/WWW/Mechanize.pm line 1403.
Awaiting your reply!
August 10th, 2012, 09:44 AM
also i have this HTML code from a button but i don't know whick value to use. Any idea? Thanks
<a id="lnkHdrnewmsg" class="btn" title="New Message" onclick="return onClkTb('newmsg');" href="#">
August 10th, 2012, 12:59 PM
I got the error message that you got about "value". I was doing something else but im still having a problem with this error.