Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Mojo::UserAgent Can't locate object method "say"

by yuppie (Initiate)
on Nov 19, 2014 at 19:13 UTC ( [id://1107808]=perlquestion: print w/replies, xml ) Need Help??

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

So, perhaps all this is a little too advanced for a newb like me, however, let me explain what I'm trying to do:

I've got a website (what.cd) that uses authentication and cookies. What I want is a script or program that logs in, scrapes the site for anything labeled "Freeleech!" and downloads the associated file, which is actually a link titled "DL" right next to the "Freeleech!" label, then moves it to a certain directory.

I was told using Mojo::UserAgent would be best, so I installed the module and started looking at the documentation (http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#Web-scraping). This is the code I have so far:
#!/usr/bin/env perl -w use strict; use warnings; use diagnostics; use Mojo::UserAgent; my $ua = Mojo::UserAgent->new; my $tx = $ua->get('what.cd'); my $cookie_jar = $ua->cookie_jar; $ua = $ua->cookie_jar(Mojo::UserAgent::CookieJar->new); say $ua->get('https://yuppie:password@what.cd/login.php')->res->body;
And here is the error it gives me: Uncaught exception from user code: Can't locate object method "say" via package "Mojo::UserAgent" at freeleech.pl line 15.

Is there a better way to go about this? I'm just trying to login right now.

Replies are listed 'Best First'.
Re: Mojo::UserAgent Can't locate object method "say"
by Loops (Curate) on Nov 19, 2014 at 19:16 UTC

    Unfortunately say isn't enabled without a use feature or version line:

    use feature 'say';

    Along with your other use lines. This is automatically enabled if you specify a minimum Perl version of v5.10 or above as well:

    use 5.010;
Re: Mojo::UserAgent Can't locate object method "say"
by blindluke (Hermit) on Nov 19, 2014 at 19:19 UTC

    say is a feature available since Perl v5.10, but it's not enabled by default. Look at the documentation:

    This keyword is available only when the "say" feature is enabled, or when prefixed with CORE:: ; see feature. Alternately, include a use v5.10 or later to the current scope.

    Just add "use v5.10;" to your code. Or replace "use strict;" with "use v5.14;" - this enables strict by default.

    - Luke

      I've got some output now! I can't comment it in here though, so I've used a paste service.

      http://hastebin.com/yicakehoxo.xml

      How can I successfully authenticate?

        First - read the response that you got. Especially this part:

        <span id="no-cookies" class="hidden warning">You appear to have cookie +s disabled.<br /><br /></span> <noscript><span class="warning">What.CD requires JavaScript to functio +n properly. Please enable JavaScript in your browser.</span><br /><br + /></noscript>

        Second, read the excellent documentation that comes with Mojo::UserAgent. Especially the examples under "scraping".

        Third, take a break to meditate.

        - Luke

        Not clear what's your problem introducing comments when creating a node here, but, worst case, you can prepare your post locally with your favorite text-editor. Include PM markup and comments in code blocks -- and when you're happy with the appearance, do a copy/paste to the text_entry box here.


        ++$anecdote ne $data


Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found