Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: using TreeBuilder in perl

by Khen1950fx (Canon)
on Jul 29, 2013 at 11:55 UTC ( [id://1046854]=note: print w/replies, xml ) Need Help??


in reply to using TreeBuilder in perl

HTML::FormatText does exactly what you want.
#!/usr/bin/perl use strict; use warnings; use utf8::all; use HTML::FormatText; use HTML::TreeBuilder::XPath; my $page = q{ <div class="contents"> &#160;<ul> <li>ChainCtrlBuildChain() : <a class="el" href="_chain_controller_8c.html#acb2c56087a2072b6445 +a54c17662d118">ChainController.c</a> </li> <li>ChainCtrlDumpChain() : <a class="el" href="_chain_controller_8c.html#a13ed5a02bf232b115b9a5 +8cdd13dadd7">ChainController.c</a> </li> <li>ChainCtrlExit() : <a class="el" href="_chain_controller_8c.html#a9e30e46ebc5411537efe9 +5a286e27cb4">ChainController.c</a> </li> <li>ChainCtrlGetBitStreamChan() : <a class="el" href="_chain_controller_8c.html#a00faa6e64ea466d4ec573 +39017e57e71">ChainController.c</a> </li> <li>ChainCtrlInit() : <a class="el" href="_chain_controller_8c.html#aed300a388eff2fa9c7565 +025982faab1">ChainController.c</a> </li> </ul> </div><!-- contents --> }; my $tree = HTML::TreeBuilder::XPath->new_from_content($page); my(@trees) = $tree->findnodes('//div[@class="contents"]'); foreach $tree(@trees) { my $formatter = HTML::FormatText->new( leftmargim => 0, rightmargin => 50, ); print $formatter->format($tree); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found