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

Hi, I'm trying to write a script that will allow me to parse a web page and replace key words. The reason for this is that the proxy server at work searches web pages you browse for key words and blocks the site if a match is found. This is very annoying especially when all I want to view is my personnal web based email. So I've got as far as being able to view the page ok, code below, but I obviously can't login etc as I don't handle cookies. Can anyone offer any suggestions as to how I could go about handling cookies etc? Note: I'm currently testing this with a gaming forum that requires login, cookies etc which is why a url is hard coded into the code.
#!/usr/bin/perl use LWP::Simple; use CGI; # load CGI routines use URI::Escape; # Module for encoding escape char in the +url. my $query = new CGI; my $URL = $query->param('url'); my $encodedURL = uri_escape($URL); $content = get($encodedURL); print $query->header; $content =~ s/games/hack/g; $content =~ s/href="/href="http:\/\/dragon.striatum.org\/cgi-bin\/let +mein.cgi?url=$encodedURL\//g; $content =~ s/img src="/img src="http:\/\/forums.actiongames.co.uk\//g +; $content =~ s/url\("/url\("http:\/\/forums.actiongames.co.uk\//g; $content =~ s/url\(t/url\(http:\/\/forums.actiongames.co.uk\/t/g; $content =~ s/action="/action="http:\/\/dragon.striatum.org\/cgi-bin\/ +letmein.cgi?url=http:\/\/forums.actiongames.co.uk\//g; print "$content\n";
Thanks Chris

Replies are listed 'Best First'.
Re: Handling cookies
by dws (Chancellor) on Aug 07, 2002 at 08:26 UTC
    So I've got as far as being able to view the page ok, code below, but I obviously can't login etc as I don't handle cookies.

    To handle cookies you'll need to forego the simplicity of LWP::Simple in favor of LWP::UserAgent plus HTTP::Cookies.

    Fortunately, others have been down this path before. See pmproxy2, and read the entire thread.

      Thanks for the advice ... I'll check it out now.
      Chris