Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

•Re: Strip HTML tags again

by merlyn (Sage)
on Jun 30, 2002 at 15:54 UTC ( #178377=note: print w/ replies, xml ) Need Help??

in reply to Strip HTML tags again

Here's an example from the eg directory in the HTML::Parser distribution:

#!/usr/bin/perl -w # Extract all plain text from an HTML file use strict; use HTML::Parser 3.00 (); my %inside; sub tag { my($tag, $num) = @_; $inside{$tag} += $num; print " "; # not for all tags } sub text { return if $inside{script} || $inside{style}; print $_[0]; } HTML::Parser->new(api_version => 3, handlers => [start => [\&tag, "tagname, '+1'"], end => [\&tag, "tagname, '-1'"], text => [\&text, "dtext"], ], marked_sections => 1, )->parse_file(shift) || die "Can't open file: $!\n";;

-- Randal L. Schwartz, Perl hacker

Comment on •Re: Strip HTML tags again
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2015-11-28 17:21 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls