Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Extracting keywords from HTML

by superfrink (Curate)
on Aug 22, 2005 at 06:11 UTC ( #485619=note: print w/replies, xml ) Need Help??


in reply to Extracting keywords from HTML

I used the following code to get the words from HTML. The javascript removal came from Re: HTML::Strip Problem.
my $text = ""; # HTML::Parser is broken on Javascript and styles (it leaves # it in the text). # # my $parser = HTML::Parser->new( # 'text_h' => [ sub { $text .= " " . shift; }, "dtext" ] # ); my $parser = HTML::Parser->new( start_h => [ sub{ $_[0]->{text}.=' '; $_[0]->{skip}++ if $_[1] +eq 'script' or $_[1] eq 'style'; } , 'self,tag' ], end_h => [ sub{ $_[0]->{skip}-- if $_[1] eq '/script' or $_[1 +] eq '/style'; } , 'self,tag' ], text_h => [ sub{ $_[0]->{text}.=$_[1] unless $_[0]->{skip}}, ' +self,dtext' ] ); $parser->parse($html_in); $text = $parser->{text};

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2023-01-31 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?