Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 6th, 2012, 12:22 AM
KuckFuggar KuckFuggar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 30 KuckFuggar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old August 6th, 2012, 03:13 AM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,084 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 43 m 12 sec
Reputation Power: 1809
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;

Reply With Quote
  #3  
Old August 9th, 2012, 06:42 AM
andreas.london andreas.london is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 64 andreas.london User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old August 9th, 2012, 02:48 PM
KuckFuggar KuckFuggar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 30 KuckFuggar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 20 m 50 sec
Reputation Power: 1
I was wondering the same.

Reply With Quote
  #5  
Old August 9th, 2012, 04:15 PM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,084 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 43 m 12 sec
Reputation Power: 1809
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.

Reply With Quote
  #6  
Old August 10th, 2012, 05:02 AM
andreas.london andreas.london is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 64 andreas.london User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #7  
Old August 10th, 2012, 09:44 AM
andreas.london andreas.london is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 64 andreas.london User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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="#">

Reply With Quote
  #8  
Old August 10th, 2012, 12:59 PM
KuckFuggar KuckFuggar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 30 KuckFuggar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > WWW::Mechanize returning errors

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap