tangent has asked for the wisdom of the Perl Monks concerning the following question:
I can't work out how to get the text of just the current node. For example, this:<ul class="top"> <li>Level 1 <ul> <li>Level 2 <ul> <li>Level 3</li> </ul> </li> </ul> </li> </ul>
gives me the following output, where all text values are concatenated:my $tree = HTML::TreeBuilder::XPath->new; $tree->parse($html); my @nodes = $tree->findnodes('//ul[@class="top"]'); for my $node (@nodes) { my @elems = $node->findnodes('li'); for my $elem (@elems) { my $text = $elem->as_text; print "$text\n"; } }
but what I want is:Level 1 Level 2 Level 3
and then drill down to the next level to get that level's textLevel 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Xpath to extract text value of nested list elements
by choroba (Cardinal) on Mar 20, 2014 at 17:09 UTC | |
by tangent (Parson) on Mar 20, 2014 at 17:19 UTC | |
by cord-bin (Friar) on Mar 21, 2014 at 08:27 UTC | |
by Anonymous Monk on Mar 21, 2014 at 08:36 UTC |