in reply to Nested div tag

I have problem in nested div tgs

Nope, your problem is you're not using a tree/DOM/xpath ... htmltreexpather.pl/HTML::TreeBuilder::XPath or xpather.pl/XML::LibXML

If you did your code could become

my @rows = $tree->findnodes(q{ //div[ @class =~ /row/ ] }); for my $row ( @rows ){ my @cells = $row->findnodes(q{ //div[ @class =~ /cell/ ] }); for my $cell ( @cells ){ Dance( $cell ); } }

Replies are listed 'Best First'.
Re^2: Nested div tag
by perlmad (Sexton) on Jul 21, 2016 at 05:51 UTC

    Thanks for your interest, but when i ran the file nothing assigned to @rows mean $#rows is -1

      Thanks for your interest, but when i ran the file nothing assigned to @rows mean $#rows is -1

      What?

        when i run the below code

        #! usr/bin/perl use strict; use warnings; use HTML::TreeBuilder::XPath; my $tree= HTML::TreeBuilder::XPath->new; $tree->parse_file(<<"HTML"); <div class="Row May-2015"> <div class="Cell month-year even"> May-2015 </div> <div class="Cell Release Date even"> 2015-06-25 </div> <div class="Cell National Mortgage Contract Rate even" +> 3.750 </div> </div> HTML my @rows = $tree->findnodes(q{//div[@class= 'Row May-2015']}); #my @rows=$tree->findnodes(q{ //div[ @class =~ /Cell/ ] }); print $#rows; for my $row ( @rows ){ my @cells = $row->findnodes(q{ //div[ @class =~ /Cell/ ] }); for my $cell ( @cells ){ #Dance( $cell ); print $cell; } }

        output be like

        [ab@linux0059 html_tree_builder]$ perl code.pl -1[ab@linux0059 html_tree_builder]$

        It does not take div node