Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Getting more out of LWP::Simple

by Dog and Pony (Priest)
on May 23, 2002 at 07:28 UTC ( #168686=note: print w/ replies, xml ) Need Help??


in reply to Re: Getting more out of LWP::Simple
in thread Getting more out of LWP::Simple

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.


Comment on Re: Re: Getting more out of LWP::Simple
Re: Re: Re: Getting more out of LWP::Simple
by Anonymous Monk on Mar 23, 2003 at 20:55 UTC
    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

      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!
        Yes it does - it's right there in the root node of this thread, and of course the fine manual.

        Makeshifts last the longest.

      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.

        Thanks alot, it works perfectly!

        I don't know how I didn't see the other post that already explained this. I think I was googled out searching through previous usenet postings for the previous 3-4 hours looking for inspiration without any joy.

        Thanks again

        Toby

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2015-07-03 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (55 votes), past polls