Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Extract Portion of HTML

by Corion (Patriarch)
on Sep 19, 2011 at 12:27 UTC ( [id://926728]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found