CoderZone.org

Category: >> Perl Code >> Extract Just The BODY Of An HTML File Bookmark and Share

<< lastnext >>

Snippet Name: Extract Just The BODY Of An HTML File

Description: Extract just the BODY of an HTML file

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: December 03rd, 2010

use LWP::UserAgent;
use HTML::TreeBuilder;
 
$ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => 'http://www.somedomain.com/');
my $res = $ua->request($req);
 
if ($res->is_success) {
  my $tree = HTML::TreeBuilder->new_from_content($res->content);
  $tree->elementify();
  my $body = $tree->find('body');
  foreach $e ($body->content_list())
  {
    print $e->as_HTML();
  }
}
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 6