html - perl look_down tag index -


i'm trying text in second li. how going in look_down. in advance :)

 <ul class="threads">    <li>one</li>    <li>two</li>    <li>three</li> </ul> <ul class="threads">    <li>one</li>    <li>two</li>    <li>three</li> </ul> <ul class="threads">    <li>one</li>    <li>two</li>    <li>three</li> </ul>  use html::treebuilder;  $tree = html::treebuilder->new; $tree->parse($url);  foreach $ul ($tree->look_down(_tag => 'ul', class => 'threads')){     foreach $li ($ul->look_down(_tag => 'li')){         print $li->as_text. "\n";     } } 

its easy https://metacpan.org/pod/html::treebuilder::xpath

#!/usr/bin/perl -- use strict; use warnings; use html::treebuilder::xpath;  $html = q{<ul class="threads">    <li>one</li>    <li>two</li>    <li>three</li> </ul> <ul class="threads">    <li>one</li>    <li>two</li>    <li>three</li> </ul> <ul class="threads">    <li>one</li>    <li>two</li>    <li>three</li> </ul>};   $tree = html::treebuilder::xpath->new; $tree->parse_content( $html ); $sec ( $tree->findnodes( q{    //ul[@class='threads']/li[2]    } ) ){     $sec->dump; } __end__ <li> @0.1.0.1   "two" <li> @0.1.1.1   "two" <li> @0.1.2.1   "two" 

this helps if don't know xpath yet :) re: htmltreexpather.pl - xpath helper, creates xpath search strings html ($version = 20120112 )


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -