Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

lwp::simple basic question about webbing

by LeGo (Chaplain)
on Jan 17, 2001 at 23:59 UTC ( [id://52585]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to run some information off of a web site. The code that I had been using is as below.
#!/usr/bin/perl -w use strict; use LWP::Simple; my @a = get("http://www.thewolfweb.com/"); print "@a";
The above works fine. When I change the 4th line to
my @a = get("http://www.thewolfweb.com/message.asp\?section\=6");
I get a use of uninitialized variable on line 5. I was curious as to what this could be.

Also if anyone is familiar with this, I might need to login somehow or represent my user ID by showing a cookie. Could this cause the error? If so or if not could someone tell me how this could be done. I don't know what module to use if I do try to do this.

Thanks much in advance.

LeGo

Replies are listed 'Best First'.
Re: lwp::simple basic question about webbing
by ichimunki (Priest) on Jan 18, 2001 at 00:15 UTC
    In addition to following merlyn's advice about switching to a different module, I'd suggest using something like
    my $a = get( $url ) || "get $url failed"; or my $a = get( $url ) or die "Couldn't get() $url: $!";
    The scalar is probably better to assign a blob of text info to. With the || operator, your variable is guaranteed to at least contain something-- if not the HTML, then an error message (since if get fails, it returns undefined). With the "die" message, your program stops altogether with an informative message-- probably better unless dying is not at all an option.
Re: lwp::simple basic question about webbing
by merlyn (Sage) on Jan 18, 2001 at 00:05 UTC
    That page needs authorization. LWP::Simple isn't that smart. You'll need to read about how to provide authorization using LWP::UserAgent.

    -- Randal L. Schwartz, Perl hacker

      This might not be directly to you merlyn but maybe a general question. I have a real hard time reading perl directions :). I did notice that my cookies file had been added to by the website I am trying to use. So I would like to somehow show this up to the server I am going into. I noticed this as possibly what I need to use but don't understand how. This is a part of LWP::UserAgent

      $ua->cookie_jar([$cookies])

      Get/set the HTTP::Cookies object to use. The default is to have no cookie_jar, i.e. never automatically add "Cookie" headers to the requests.

      I have four lines of stuff from this website. Would I put them into an array, would I put the cookies in $cookies and have many of the above lines of code, or how might I go about showing them my cookies that the have set?

      LeGo

        If you are using Netscape, you can use HTTP::Cookies to have your LWP::UserAgent client read and write from your actual Netscape cookie files without needing to cut and paste the cookie string into your code:

        #!/usr/bin/perl -w use strict; use HTTP::Cookies; use LWP::UserAgent; #Set path to your Netscape Cookie files my $cookie_jar = HTTP::Cookies::Netscape->new( File => "$ENV{HOME}/.netscape/cookies", AutoSave => 1, ); #Create a User Agent, and tell it to store cookies my $ua = LWP::UserAgent->new; $ua->cookie_jar($cookie_jar); #...

        If you aren't using Netscape, then you will have to explicitly set the cookies in the $cookie_jar object, which you can do using the HTTP::Cookies::set_cookie() method.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found