Thread lwp tokeparser HTML::Parser haumichtot: newbie braucht hilfe (1 answers)
Opened by Gast at 2007-01-25 11:46

renee
 2007-01-25 11:58
#9547 #9547
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
ungetestet:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/perl
use strict;
use warnings;
use HTML::Parser;
use Data::Dumper;

my @numbers;
my $string = qq~Dein HTML~;

my $p = HTML::Parser->new();
$p->{numbers} = [];
$p->handler(start => \&start_handler,"tagname,attr,self");
$p->handler(end => \&end_handler,"self,tagname");
$p->handler(text => \&text_handler, "self,dtext");
$p->parse($string);

print Dumper(\@numbers)

sub start_handler{
my ($tag,$attr,$self) = @_;
return if($tag ne 'input');
return unless($attr->{name} =~ /^Button\d+$/);
$self->{bool} = 1;
}

sub end_handler{
my ($self,$tag) = @_;
if($tag eq 'td'){
$self->{bool} = 0;
push @numbers,$self->{numbers} if(scalar @{$self->{numbers}} > 0);
$self->{numbers} = [];
}
}

sub text_handler{
my ($self,$text) = @_;
$text =~ s/^\s+//;
$text =~ s/\s+$//;
if($self->{bool} and $text =~ /^\d+$/){
push @{$self->{numbers}},$text;
}
}


Wegen der Registrierung kannst Du mir mal ein Mail mit Deinem Wunsch-Nickname schicken: perl {klammeraffe} renee {minus} baecker {punkt} de

edit: Zu CPAN:HTML::Parser habe ich mal einen Wiki:Artikel geschrieben...\n\n

<!--EDIT|renee|1169719174-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread lwp tokeparser HTML::Parser haumichtot: newbie braucht hilfe