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
| [reply] [Watch: Dir/Any] [d/l] [select] |
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. | [reply] [Watch: Dir/Any] [d/l] |
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
| [reply] [Watch: Dir/Any] |
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! |
---|
| [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] |