Perl WWW:Mechanize failing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl WWW:Mechanize failing
# 1  
Old 02-12-2010
Perl WWW:Mechanize failing

So, I've just started learning Perl, and I've decided to read up on some modules. I encountered WWW::Mechanize, which interests me, so I decided to try out a couple of basic tutorials. One of them is found here. I tried what seems a very basic case:

Code:
#!/usr/bin/perl
use WWW::Mechanize;
$url = 'http://www.google.com';
$m->get($url);
$link = $m->find_link(text => 'Advanced Search');
print "The Google advanced search URL is:  $link->url()\n";

Strict pragma is not being used, so this should be fairly forgiving. The error message I get is:

Code:
Can't call method "get" on an undefined value at ./googlemech.pl line 4.

So, it seems reasonable to make sure that the value $url is actually being properly assigned. I commented out the last 3 lines and added this after the $m assignment lines:

Code:
print "$url\n"

It printed "http://www.google.com" (without quotes) properly. To back this up, I explicitly stated "http://www.google.com" in the "get" portion, and got the same error. So, it appears that the problem is not with variable assignment. That suggests that perhaps the WWW::Mechanize module isn't installed. So, I did "perldoc perllocal" and got:

Code:
Fri Feb 12 13:29:52 2010: "Module" WWW::Mechanize

with the usual accompanying information. I did the installation through CPAN about an hour ago. It appears to be installed and available, and yet the script fails. Do I have to do anything to "initialize" the module, so to speak? If not, what in the world might be going wrong with this? Many thanks in advance.
# 2  
Old 02-12-2010
Quote:
Originally Posted by treesloth
Code:
#!/usr/bin/perl
use WWW::Mechanize;
$url = 'http://www.google.com';
$m->get($url);
$link = $m->find_link(text => 'Advanced Search');
print "The Google advanced search URL is:  $link->url()\n";

Strict pragma is not being used, so this should be fairly forgiving. The error message I get is:

Code:
Can't call method "get" on an undefined value at ./googlemech.pl line 4.

The error message is pretty telling. Line 4 is
Code:
$m->get($url);

, and somewhere in there is an undefined value. You've established that it ain't $url, so what's left?

The problem with the second example in the given tutorial is that it isn't runnable, unless you apply some common sense and re-use a line from the first example:
Code:
my $m = WWW::Mechanize->new();

Include that line before you call any methods on $m (which is undefined otherwise), and you should be fine.

Also, reading through perldoc WWW::Mechanize::Examples might give a hint or two.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

PERL DBD make test on Linux failing

I am installing Oracle DBD to PERL 5.16.3 and during make test , I am running into this error :rm -f blib/arch/auto/DBD/Oracle/Oracle.so LD_RUN_PATH="/opt/oracle/product/11.2.0/racdb11204/lib" gcc -m32 -shared -O2 -L/usr/local/lib -fstack-protector Oracle.o dbdimp.o oci8.o -o... (3 Replies)
Discussion started by: talashil
3 Replies

2. Shell Programming and Scripting

[Ubuntu / PERL ]Problem installing WWW::Mechanize mod

Hello everyone, I've got some problem intalling a perl module. The installation is well done as you can see below. gueg@ux31:~$ sudo apt-get install libwww-mechanize-perl Lecture des listes de paquets... Fait Construction de l'arbre des dépendances Lecture des informations d'état...... (4 Replies)
Discussion started by: tot94
4 Replies

3. Shell Programming and Scripting

Reading URL using Mechanize and dump all the contents of the URL to a file

Hello, Am very new to perl , please help me here !! I need help in reading a URL from command line using PERL:: Mechanize and needs all the contents from the URL to get into a file. below is the script which i have written so far , #!/usr/bin/perl use LWP::UserAgent; use... (2 Replies)
Discussion started by: scott_cog
2 Replies

4. Shell Programming and Scripting

WWW:::Mechanize - Anyone have sample scripts?

Hello, I am trying to get to learn WWW::Mechanize & have found alot of sample scripts (that dont work) so am wondering if anyone has any that do, I basically just learn from stripping current bits out seeing how they work etc.. etc.. - if anyone can point me to somewhere that has a few good... (0 Replies)
Discussion started by: t0mb
0 Replies

5. Shell Programming and Scripting

ps -ef failing sometimes

Hi Everyone, we have a shell script "DLP_recv.sh" that has below command which is supposed to return the number of active instances of itself, which means of there is no other instance then commad would return 1 (for the current instance). The problem is that it sometimes it returns 0 which is... (3 Replies)
Discussion started by: guycool
3 Replies

6. Programming

WWW::Mechanize Question

We've been running perl scripts using the www::mechanize module on a linux box with no issues, however we just implemented the same scripts on an aix machine, aix 6.1, perl 5.8.8, and I am running into the issue with Content_Encoding: gzip in the returned html. I can't read it in that it is coming... (0 Replies)
Discussion started by: islanderman
0 Replies

7. UNIX for Dummies Questions & Answers

www.caldera.com

what happened with www.caldera.com or www.sco.com? i cant access the sites 10 days now. I try from my home pc, from internet cafe,from my work. Can you access these sites? I live in Greece. (2 Replies)
Discussion started by: kalco
2 Replies

8. News, Links, Events and Announcements

www.perl.com (just to make this a legit post)

OMGosh!!! PERL OWZORZ ME!!!!!!! ok ok let me take a deep breath..... altho i have just started learning perl and scripting in perl. this is like the BOMB!!!. you remember when you started shell scripting and you felt limitless. this is how i feel now. how could i have ever lived my life... (4 Replies)
Discussion started by: Optimus_P
4 Replies
Login or Register to Ask a Question