Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Removing Javascript

by domm (Chaplain)
on Jan 04, 2003 at 13:00 UTC ( #224247=note: print w/ replies, xml ) Need Help??


in reply to Removing Javascript

Jet another way, using HTML::Tree:

Please note that this doesn't handle the unescaped closing script tag in document.write. I'd suggest running tidy on the input before passing it to the parser.

#!/usr/bin/perl -w use strict; use HTML::Tree; my $doc = <<EOF; <html> <head> <script language="Javascript"> document.write("Don't forget your &lt;/script&gt; tag! It's important! +"); </script> </head> <body> This is just some text. </body> </html> EOF my $root=HTML::TreeBuilder->new(); $root->parse($doc); $root->eof; foreach my $n ($root->descendants) { next unless $n->tag; # skip text nodes $n->delete if $n->tag eq 'script'; } print $root->dump; # prints structure print $root->as_HTML # prints as HTML
-- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}


Comment on Re: Removing Javascript
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2015-07-06 07:57 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 (70 votes), past polls