The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
WWW::Mechanize returning errors
Discuss WWW::Mechanize returning errors in the Perl Programming forum on Dev Shed. WWW::Mechanize returning errors Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 6th, 2012, 12:22 AM
|
|
Contributing User
|
|
Join Date: Jul 2012
Posts: 30
Time spent in forums: 10 h 20 m 50 sec
Reputation Power: 1
|
|
|
WWW::Mechanize returning errors
I am trying to use WWW::Mechanize in a simple script and it all ways comes up with an error.
Code:
#!/usr/bin/perl
use WWW::Mechanize;
$url = 'http://www.google.com';
$m->get($url);
$m->form_name('f');
$m->field('q', 'test search');
$response = $m->submit();
print $response->content();
the error is
Code:
Can't call method "get" on an undefined value at /home/Documents/spider/spider1/mainspider3.pl line 4.
|

August 6th, 2012, 03:13 AM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
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:
Code:
my $m = WWW::Mechanize->new;
|

August 9th, 2012, 06:42 AM
|
|
Contributing User
|
|
Join Date: Jul 2012
Posts: 64
Time spent in forums: 21 h 6 m 55 sec
Reputation Power: 1
|
|
|
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?
thanks
|

August 9th, 2012, 02:48 PM
|
|
Contributing User
|
|
Join Date: Jul 2012
Posts: 30
Time spent in forums: 10 h 20 m 50 sec
Reputation Power: 1
|
|
|
I was wondering the same.
|

August 9th, 2012, 04:15 PM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
Quote: | Originally Posted by andreas.london 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? |
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.
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:
Code:
$mech->forms
$mech->form_number($number)
$mech->form_name( $name )
$mech->form_id( $name )
$mech->form_with_fields( @fields )
Get all the forms
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
|
|
Contributing User
|
|
Join Date: Jul 2012
Posts: 64
Time spent in forums: 21 h 6 m 55 sec
Reputation Power: 1
|
|
I see. yea, i found the form names and ids!
Unfortunately i still have an error when im using this code:
Code:
#!/usr/bin/perl
use WWW::Mechanize;
my $mech = WWW::Mechanize->new;
$url = 'https://demo01.service-now.com/navpage.do';
$mech->get($url);
$number = 1;
$mech->form_number($number);
$mech->field("user_name", "itil");
$mech->filed("user_password", "itil");
$mech->click();
$mech->get($url);
ERROR:
Code:
Can't call method "value" on an undefined value at C:/Perl/lib/WWW/Mechanize.pm line 1403.
Thanks a lot.
Awaiting your reply!
|

August 10th, 2012, 09:44 AM
|
|
Contributing User
|
|
Join Date: Jul 2012
Posts: 64
Time spent in forums: 21 h 6 m 55 sec
Reputation Power: 1
|
|
also i have this HTML code from a button but i don't know whick value to use. Any idea? Thanks
Code:
<a id="lnkHdrnewmsg" class="btn" title="New Message" onclick="return onClkTb('newmsg');" href="#">
|

August 10th, 2012, 12:59 PM
|
|
Contributing User
|
|
Join Date: Jul 2012
Posts: 30
Time spent in forums: 10 h 20 m 50 sec
Reputation Power: 1
|
|
|
I got the error message that you got about "value". I was doing something else but im still having a problem with this error.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|