I sometimes find myself needing to extract the HTML from between the body tags of a document. The following function takes a filename, file handle, or a scalar reference (with the scalar containing the HTML).
use HTML::TokeParser::Simple 1.4; print get_contents( $some_html ); sub get_contents { my $file = shift; my $parser = HTML::TokeParser::Simple->new( $file ) or die "Cannot create parser for ($file): $!"; my $html = ''; 1 while ! $parser->get_tag->is_start_tag('body'); while ( my $token = $parser->get_token ) { last if $token->is_end_tag('body'); $html .= $token->as_is; } return $html; }
In reply to Extract Web page contents by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |