in reply to Re: Extract Portion of HTML
in thread Extract Portion of HTML

In addition another variant on the same theme using HTML::TreeBuilder::XPath together with HTML::Selector::XPath:

#!perl -w use strict; my $html = '<html> --stuff-- <head> --more stuff-- </head> <body> --still more stuff-- <div class="myBody"> --all the stuff I want, which might include div tags, too-- </div> --yet more stuff-- </body> </html>'; use HTML::Selector::XPath qw(selector_to_xpath); use HTML::TreeBuilder::XPath; my $t = HTML::TreeBuilder::XPath->new_from_content($html); my $q = selector_to_xpath('div.myBody'); print $_->as_HTML for ($t->findnodes($q)); # <div class="myBody"> --all the stuff I want, which might include div + tags, too-- </div>

The same should also be fairly simple using App::scrape, but the API currently does not allow for returning node elements (and the corresponding DOM tree), only plain text.