Hi Group-

(Please excuse me if this post is a duplicate - free news servers
aren't reliable)

I'm trying to figure out how to recursively scan an HTML tree.
Through
trial and error I've arrived at the solution below except I'm stumped
on how
to recurse into the next level.  I can't seem to find a way to
determine if
an item in the content_list is an entry point into the next deeper
level
(that is, not a leaf node).  My progress so far is shown in the code
snippet
below.  Can anyone provide any clues to what code I can sub for "CAN
RECURSE
DEEPER" in the if() statement?

Thanks, John.

################
sub recurse
{
    my @children = @_;

    my $itemCount = @children;

    for(my $i = 0; $i < $itemCount; $i++)
    {
        my $item = $children[$i];

        my $s = $item->as_text();
        my $d = $item->depth();

        print "Position $i, depth=$d, '$s'\n";

        if("CAN RECURSE DEEPER")
        {
            recurse($item->content_list);
        }
    }
}

################
sub main
{
    # $htmlFile is the HTM file spec string

    # Parse the input file into an HTML tree
    my $tree = HTML::TreeBuilder->new();
    $tree->parse_file($htmlFile);
    recurse($tree->content_list);
    $tree->delete;
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to