in reply to Re: html::treebuilder problem
in thread html::treebuilder problem

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: html::treebuilder problem
by GrandFather (Saint) on Dec 20, 2007 at 21:11 UTC

    The problem seems to be that you are only looking for the first match (look_down is in scalar context) and are somewhat abusing the parameter processing of look_down to hook out the information you want. The better approach is something like:

    use strict; use warnings; use HTML::TreeBuilder; my $p = HTML::TreeBuilder->new; my @content = <DATA>; $p->parse_content(@content); for my $match ($p->look_down('_tag' => 'div', 'class' => 'subsection' +)) { my $prop = $match->look_down ('class', 'box_profile_info_small_hea +ding'); my $value = $match->look_down ('class', 'box_profile_info_small_co +ntent'); next unless $prop && $value; print $prop->as_text (), ' => ', $value->as_text (), "\n"; }

    which with your sample data prints:

    About Me => you will know me better if you want to... Who I'd Like To Meet => i'd like to meet all the world... Sexual Orientation => Straight Drinker => No Smoker => Socially

    Perl is environmentally friendly - it saves trees
      very nice,that helps very much. I didn't pay enough attention to the docs. sorry for bothering with the question