Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by Anonymous Monk
on Mar 23, 2003 at 20:55 UTC ( #245309=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re: Re: Re: Getting more out of LWP::Simple
Select or Download Code
Re: Re: Re: Re: Getting more out of LWP::Simple
by jasonk (Parson) on Mar 23, 2003 at 21:18 UTC

    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.

Re^4: Getting more out of LWP::Simple (import it)
by Aristotle (Chancellor) on Mar 23, 2003 at 22:44 UTC
    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://245309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-11-26 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (162 votes), past polls