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 43 44 45 46 47 48 49 50 51 52 53 54 55 56
   |  
#!c:/perl/bin/Perl.exe
 
use strict;
use diagnostics;
use LWP::Simple;
use Data::Dumper;
use HTML::Parser ();
 
my $code = get('index.html');
 
{
  my $in_object = 0;
 
  sub start {
     my ($tag,$args, $text) = @_;
      if( not $in_object ){
          if ($tag eq 'div') {
            if ($args->{class} eq 'titreblanc' || $args->{class} eq 'texteblancgras') {
              $in_object++;
            }
          } elsif ($tag eq 'td') {
            if ($args->{bgcolor} eq '#DCDFE7') {
              $in_object++;
            }
          }
      } else {
        print FILE $text;
      }
  }
 
  sub end {
      my ($tag, $text) = @_;
      if( $in_object ) {
        $in_object-- if( $tag eq 'div' || $tag eq 'td');
      }
  }
 
  sub text {
      my $text = shift;
      if( $in_object ){
        print FILE $text."<br>";
      }
  }
}
open (FILE,">C:/sanstag.txt") || die "Impossible d'écrire : $!";
 
my $p = HTML::Parser->new( api_version => 3,
                         start_h => [\&start, "tagname,attr,text"],
                         end_h   => [\&end,   "tagname, text"],
                         text_h => [\&text, "text"]
                       );
 
$p->parse( $code );
 
close(FILE); | 
Partager