Thread Nur tatsächliche Texte aus HTML parsen (21 answers)
Opened by Nordlicht at 2007-05-09 20:04

renee
 2007-05-14 12:08
#29014 #29014
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Das hier dürfte eine ganz gute Basis sein:
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
23
24
25
26
27
28
#!/usr/bin/perl

use strict;
use warnings;
use HTML::Parser;
use LWP::Simple;
use Data::Dumper;

my $url = '[URL=http://foo-magazin.de]http://foo-magazin.de[/URL]';
#my $url = '[URL=http://de.wikipedia.org/wiki/Perl]http://de.wikipedia.org/wiki/Perl[/URL]';
my $content = get($url);

if( $content ){
    my @text_parts;

    my $parser = HTML::Parser->new();
    $parser->ignore_elements(qw/head/);
    $parser->handler( 
        text => sub{ 
            push @text_parts, grep{!/^[\s\n]*$/}@_ 
        },
        "dtext" 
    );
    $parser->handler( comment => sub {""} );
    $parser->parse($content);

    print Dumper(\@text_parts);
}
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 Nur tatsächliche Texte aus HTML parsen