Thread Code für HTML::Parser korrekt?
(19 answers)
Opened by Gast at 2010-03-01 19:48
Mit diesen actionbasierten Parsern bin ich nicht warm geworden. Versuch mal das, weiß nicht ob das so funktioniert und auch so gedacht ist.
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 use Data::Dumper; my $parser->handler( start => \&start_handler, 'tagname, self' ); $parser->parse( $content ); print Dumper($parser->{_my_vars}); sub start_handler { return if shift ne 'li'; my $self = shift; $self->handler( start => \&title_handler, 'tagname, attr, self' ); } sub title_handler { my( $tagname, $attr, $self ) = @_; return if $tagname ne 'a'; return unless $attr->{title}; my $cnow=$self->{_my_vars}->{count} || 0; $self->{_my_vars}->{count}++; $self->handler( text => sub{ $self->{_my_vars}->[$cnow]->{text} =shift(); }, 'self, dtext' ); $self->{_my_vars}->[$cnow]->{href}=$attr->{href}; } |