Search code examples
perlclassfor-loophtml-tree

Specify multiple classes in HTML::Element's look_down routine Perl?


I am using HTML::TreeBuilder to parse some HTML.

Can you specify multiple classes in the 'look_down' routine?

For in stance when searching through HTML using-

for ( $tree->look_down( 'class' => 'postbody'))

I also was to search for an additional class 'postprofile' in the same loop.

Is there a way of doing this without having to use a new -for ( $tree->look_down( 'class' => 'postprofile' ))

As this brings back 2 sets of results whereas I only want one merged set.

I tried using - for ( $tree->look_down( 'class' => 'postbody||postprofile')) However this did not work,

Thank you in advance.


Solution

  • Try using a pattern instead of a string, i.e.,

    $tree->look_down( 'class' => qr/^(?:postbody|postprofile)$/)