Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: using TreeBuilder in perl

by Khen1950fx (Canon)
on Jul 29, 2013 at 11:55 UTC ( #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); }


Comment on Re: using TreeBuilder in perl
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2015-07-28 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls