Thread Code für HTML::Parser korrekt? (19 answers)
Opened by Gast at 2010-03-01 19:48

Gast Gast
 2010-03-01 19:48
#133831 #133831
Hallo, ich vermute, daran gibt es nichts auszusetzen:

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 HTML::Parser;
my $parser = HTML::Parser->new;
$parser->handler( start => \&start_handler, 'tagname, self' );
$parser->parse( $content );


sub start_handler {
    return if shift ne 'li';
    my $self = shift;

    $self->handler( start => \&title_handler , 'tagname, attr' );

    sub title_handler {
        return if shift ne 'a';  
        my $title = shift->{title};
        return unless $title;
        if ( $title =~ /\Q$name\E/sm ) { 
            say $title; 
        } 
    }
}   


//Modedit: Titel geändert
Last edited: 2010-03-02 10:37:06 +0100 (CET)

View full thread Code für HTML::Parser korrekt?