Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

WWW:Mechanize and Windows

by Akira71 (Scribe)
on Aug 12, 2003 at 15:50 UTC ( #283238=perlquestion: print w/replies, xml ) Need Help??

Akira71 has asked for the wisdom of the Perl Monks concerning the following question:

***Major Newby Question Warning***

OK, now that the warning is in place. I have simple question I was hoping someone can give me direction on.
I have recently installed the WWW:Mechanize PPM package for Activestate Perl on Windows. This is version .48 of the package.
First I seem to be having some trouble getting the latest version to build so I installed the prior version.
Next I am getting this problem when I try to isntantiate a new class.
Can't locate object method "requests_redirectable" via "WWW::Mechanize +" (perhaps you forgot to load "WWW::Mechanize"?) at C:/Perl/site/lib/WWW +/ line 156.

The offending code in the PM is this.

sub new { my $class = shift; my %default_parms = ( agent => "WWW-Mechanize/$VERSION", cookie_jar => {}, ); my $self = $class->SUPER::new( %default_parms, @_ ); $self->{page_stack} = []; $self->{quiet} = 0; $self->env_proxy(); push( @{$self->requests_redirectable}, 'POST' ); return bless $self, $class; }

The offending line being the push.
I feel as though I am missing something here, but I have isntalled every related package I can think of. I must get some screen scraping done soon and cannot get cUrl to install on windows (libcurl at least, not the command line version) and now Mechanize. Perhaps there is something better?
Can the wonderful monks of Perl save me from doing this in C++ (where I have a library)?

Replies are listed 'Best First'.
Re: WWW:Mechanize and Windows
by jdtoronto (Prior) on Aug 12, 2003 at 17:05 UTC

    I haven't looked into this particular problem, but every time I have had those errors it is due to a badly formed reference to the module in my code.

    It might help if we could see the code that caused the error in the first place.


      Hello John, Well all the examples cause the problem from the example.pod file. Here is the shortest one, written by Randal himself. I was running this code to test the module out and that is when I ran into the problem. In other words, I have not even gotten to my own code yet. I have also been unsuccesfull in getting the latest version of this module to install which is why I went to the prior version.
      use strict; $|++; use WWW::Mechanize; use File::Basename; my $m = WWW::Mechanize->new; $m->get(""); my @top_links = @{$m->links}; for my $top_link_num (0..$#top_links) { next unless $top_links[$top_link_num][0] =~ /^http:/; $m->follow($top_link_num) or die "can't follow $top_link_num"; print $m->uri, "\n"; for my $image (grep m{^http://store4}, map $_->[0], @{$m->links}) { my $local = basename $image; print " $image...", $m->mirror($image, $local)->message, "\n" } $m->back or die "can't go back"; }

      This is the very line that causes it:
      my $m = WWW::Mechanize->new;

      Well any help is always appreciated. Thank you very much!

        Using Windows 2000, ActiveState perl v5.6.1 and WWW::Mechanize (version 0.43)-- I cut and pasted your code and it runs perfectly on my system. So, perhaps the problem is in your version of Mechanize, or perhaps you're missing something else on your system. When I run the code through my debugger, it does tap into LWP::UserAgent. Could you have a problem there? (Seems unlikely, but leave no stone unturned.)

        I know this isn't much help. But don't give up hope, the code can work.

Re: WWW:Mechanize and Windows
by RMGir (Prior) on Aug 12, 2003 at 16:32 UTC
    Keep in mind I know nothing about WWW::Mechanize, which sounds like the name of a world war 3 tank game.

    What you were doing was trying to invoke a method named requests_redirectable on your $self object, and treat its return value as an array reference.

    You probably meant to use:

    # note the extra layer of {} push( @{$self->{requests_redirectable}}, 'POST' );

      Thank you Mike for the answer.
      I went ahead and made the change only to get an error further down the page. The code I displayed, was actually code from the WWW::Mechanize PM and was not written by me. It has been around a while and even Randall Schwartz (sp?! sorry if wrong) has included a demo in the example.pod file. I cannot help but feel there is something else missing and that this should compile.

      For completeness the error I get later when making the changes suggested above is:
      C:\Perl Dev\Screen Scraper Test>perl Can't locate object method "get" via kage "WWW::Mechanize" (perhaps yo +u forgot to load "WWW::Mechanize"?) at C:/Perl/site/lib/WWW/Mechanize line 183.

      Line 183 of the file is:
      sub get { my $self = shift; my $uri = shift; $uri = $self->{base} ? URI->new_abs( $uri, $self->{base} ) : URI->new( $uri ); return $self->SUPER::get( $uri, @_ ); }

      The return $self line exactly.
      Thank you for you help though. It is always appreciated.
        I'm sorry, I have no idea what the problem is.

        However, looking at CPAN, I see that WWW::Mechanize is up to version 0.57.

        Maybe the problem you're running into is fixed in that release? In any case, you're more likely to be able to get help from the maintainer if your problem is happening with the latest release.

        That latest version was release on July 31 of this year, so it looks like this module is still being actively maintained.

Re: WWW:Mechanize and Windows
by mjamesruggiero (Acolyte) on Nov 26, 2003 at 22:33 UTC
    Akira: I am having the same exact problem. I copied the www.despair example and got the same error. If you found a solution, please let me know! thanks, mjr
      Hi, I am also facing same problem. If you found the solution for this, please let me know. Thanks & Regards, N.Arul Can't locate object method "get" via package "WWW::Mechanize" (perhaps you forgo t to load "WWW::Mechanize"?) at C:/Users/Matti/Desktop/ActivePerl- n32-x86-multi-thread/ActivePerl/Perl/lib/WWW/ line 352.

        WWW::Mechanize is based on LWP::UserAgent, which comes with LWP. It sounds as if you do not have this installed. How did you install WWW::Mechanize? Please install it through PPM or CPAN, as these will pick up all other modules needed.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://283238]
Approved by Kanji
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2022-06-27 11:39 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (88 votes). Check out past polls.