Unfortunately, this is the OLD way to use HTML::Parser, I haven't learned the new way yet (bad jeffa!). But this should get you going.use strict; use LWP::Simple; use HTML::Parser; # get the content of the web page my $content = get("http://www.google.com/"); # instaniate a new parser and let it crunch our data my @lines; my $parser = new MyParser; $parser->parse($content); { package MyParser; use base qw(HTML::Parser); # this method supplies the text, no tags :) sub text { my ($self, $origtext) = @_; print $origtext, "\n"; } }
UPDATE: If you want to store the contents in a variable, just add
Then, inside the text subroutine replace the print line with:my $stripped_html; # or whatever you wanna call it
I would recommend using an array instead, however:$stripped_html .= $origtext;
UPDATE: UPDATE: just do what merlyn says :)my @stripped_html; #and inside &text push(@stripped_html, $origtext);
Jeff
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)
In reply to (jeffa) Re: How to get HTML::Parser to return a line of parsed text
by jeffa
in thread How to get HTML::Parser to return a line of parsed text
by donfreenut
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |