Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: HTML::TokeParser Frustration

by wfsp (Abbot)
on Oct 17, 2008 at 07:12 UTC ( #717674=note: print w/replies, xml ) Need Help??


in reply to HTML::TokeParser Frustration

graff has answered your question. fwiw I find HTML::TokeParser::Simple can, imo, help make this sort of task easier.
#!/usr/bin/perl use strict; use warnings; use HTML::TokeParser::Simple; my $sample_HTML = <<EOD; <HTML> blah. <CDATA> Just some random whatever. It might have some <b>real</b> HTML like a +table or CSS styling or even some <H1>IMPORTANT</H1> words. Maybe even a form <form method= +post>...</form> </CDATA> </HTML> EOD my $p = HTML::TokeParser::Simple->new(\$sample_HTML) or die qq{parse failed\n}; my ($in_cdata, $cdata); while (my $t = $p->get_token){ $in_cdata++, next if $t->is_start_tag(q{cdata}); $in_cdata--, next if $t->is_end_tag(q{cdata}); next unless $in_cdata; $cdata .= $t->as_is; } print $cdata;
Just some random whatever. It might have some <b>real</b> HTML like a +table or CSS styling or even some <H1>IMPORTANT</H1> words. Maybe even a form <form method= +post>...</form>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2021-10-27 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (94 votes). Check out past polls.

    Notices?