in reply to How to get HTML::Parser to return a line of parsed text
Personally, I like japhy's answer, but since you are
wanting to know how to do it with HTML::Parser, here is
yet another way.
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)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: How to get HTML::Parser to return a line of parsed text
by merlyn (Sage) on Feb 06, 2001 at 20:20 UTC | |
by donfreenut (Sexton) on Feb 06, 2001 at 20:31 UTC | |
by davorg (Chancellor) on Feb 06, 2001 at 21:03 UTC | |
by merlyn (Sage) on Feb 06, 2001 at 21:21 UTC | |
by Anonymous Monk on Jan 04, 2008 at 16:39 UTC | |
by arturo (Vicar) on Feb 06, 2001 at 23:33 UTC | |
Re: Re: How to get HTML::Parser to return a line of parsed text
by donfreenut (Sexton) on Feb 06, 2001 at 20:13 UTC |
In Section
Seekers of Perl Wisdom