Gossamer Forum
Home : General : Perl Programming :

LWP module and Javascript?

Quote Reply
LWP module and Javascript?
I am trying to grab the content of a site (obviously with their consent) using this code:

use LWP::Simple;

$html = get($url);
@html = split(/\n/,$html);

$count = 0;
foreach $line(@html) {
$line =~ s/\'/\\\'/g;
$line =~ s/\n/<br>/g;
print "document.writeln('$line');\n";


Then calling this script using the script tag in my html document.

<script src="http://yourdomain.com/cgi-bin/grab.cgi?http://site-to-grab.com/*html/*cgi etc"></script>

This works fine with the any simple HTML document, but now what I am facing the problem is that the file I am trying to grab contains a lot of javascript in it. So when I try to put javascript into javascript ( "document.writein('$line');\n") it gives me error, I m very weak in regex, I know the solution lies simply in removing

$line =~ s/javascript_tags/replace_them_with_html_comment/g;

or there any other way to get this done?

Thanks in advance,


Last edited by:

zeshan: May 17, 2003, 12:50 PM
Quote Reply
Re: [zeshan] LWP module and Javascript? In reply to

$line =~ s/</&lt;/g;

Btw, instead of using $count++ inside your loop, use:

my $count = scalar @html;

Last edited by:

Paul: May 17, 2003, 2:23 PM