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

Re: Getting more out of LWP::Simple

by ignatz (Vicar)
on May 21, 2002 at 20:27 UTC ( [id://168259]=note: print w/replies, xml ) Need Help??


in reply to Getting more out of LWP::Simple

D&P,

I think that there is a lot of great information in here that would make this node a very welcome addition to Tutorials. Tye has informed me that there is no such thing as "move to tutorials" as I had requested and that the best thing to do is to ask the author to repost it under tutorials, and so I am doing so.

()-()
 \"/
  `                                                     

Replies are listed 'Best First'.
Re: Re: Getting more out of LWP::Simple
by Dog and Pony (Priest) on May 23, 2002 at 07:28 UTC
    Done. I've reposted it under Tutorials here.

    I'd like to add a big thank you, I am very flattered by this response. :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
      This looks exactly like what i need, but being a bit of a perl novice I'm still not able to use this advice as I'd like.

      I am trying to write a web page that will allow the surfer to enter a url, fetch the page content, then process the content (partially translate it into German**.), and produce a new copy of the now modified page. This would be fine if all the pages the surfer wanted were behind the university firewall were my proto-script lives. Of course, I want them to be able to access the entire web. If anyone could explain why the LWP::UserAgent method below doesn't solve my problem I'd be very grateful.

      **It's for intermediate learners of english

      Toby

      ###################################### #!/usr/local/bin/perl use URI; use LWP::Simple; print "Content-type:text/html\n\n"; $ua->proxy('http', 'http://$myproxy:$myport'); my $content = get("http://news.bbc.co.uk"); #Store the output of the web page (html and all) in content if (defined $content) { #$content will contain the html associated with the url mentioned +above. print $content; } else { #If an error occurs then $content will not be defined. print "Error: Get stuffed"; } ############################################

      Edit: Added <code> tags. larsen

        You need to import LWP::Simple's $ua before you can use it. And because you're explicitly requesting the export of a certain symbol, you have to ask for all of the ones you need. So replace your use line with
        use LWP::Simple qw($ua get);

        Makeshifts last the longest.

        Because you never defined $ua, so the proxy call doesn't do anything. LWP::Simple doesn't provide an interface to set the proxies in this manner, you need to do it by setting the $http_proxy environment variable instead...

        #!/usr/bin/perl -w use strict; use LWP::Simple $env{http_proxy} = "http://myproxy:myport"; my $content = get("http://news.bbc.co.uk"); if($content) { print $content; } else { print "Error: Get stuffed"; }

        We're not surrounded, we're in a target-rich environment!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found