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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| #!/usr/bin/perl -w
use strict;
use HTML::Parser 3.00 ();
# Definition des attributs de HTML::Parser
my %inside;
my $ligne;
sub tag
{
my($tag, $num) = @_;
$inside{$tag} += $num;
print DETAIL_SOCIETE ""; # not for all tags
}
sub text
{
return if $inside{script} || $inside{style};
$_[0] =~ s/^\s+|\s+$//mg;
print DETAIL_SOCIETE $_[0];
}
my $p = HTML::Parser->new(api_version => 3,
handlers => [start => [\&tag, "tagname, '+1'"],
end => [\&tag, "tagname, '-1'"],
text => [\&text, "dtext"],
],
marked_sections => 1,
);
#Ouverture du fichier contenant la liste des fichiers à traiter "liste_ID.txt"
#et creation du fichier de synthèse "synthese.txt"
open(LISTE_SOCIETE,"liste_ID.txt") || die ("erreur d'ouverture du fichier liste_ID.txt");
open(SYNTHESE,">>synthese.txt") || die ("erreur avec le fichier synthese.txt");
#lecture de toutes les lignes de LISTE_SOCIETE
while(chomp($ligne = <LISTE_SOCIETE>)){
#effacement de l'ancien fichier contenant les informations relatives à la societe en cours.
unlink ("detail_societe.txt");
#création du fichier qui contiendra les informations relatives à la société en cours.
open(DETAIL_SOCIETE,">detail_societe.txt") || die ("erreur de creation du fichier detail_societe.txt");
#Utilisation du module HTML:Parser et stockage dans le fichier DETAIL_SOCIETE.
$p->parse_file($ligne.'.html') || die "Can't open file: $!\n";;
#Fermeture et Reouverture du fichier "detail_societe.txt" pour revenir en debut de fichier.
close(DETAIL_SOCIETE);
open(DETAIL_SOCIETE,"detail_societe.txt") || die ("erreur d'ouverture du fichier detail_societe.txt");
#Selection et inscription des informations interessantes dans le fichier synthese.txt
while(<DETAIL_SOCIETE>){
if (/Raison sociale :(.*?)Activité détaillée :/gs){
print SYNTHESE "$1";
}
else{
print SYNTHESE "N.C.";
}
if (/Activité détaillée :(.*?)Code APE :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Code APE :(.*?)Effectif salarié :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Effectif salarié :(.*?)Ville :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Ville :(.*?)Code postal :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Code postal :(.*?)Adresse :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Adresse :(.*?)Téléphone :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Téléphone :(.*?)Fax :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Fax :(.*?)Groupe :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Groupe :(.*?)Certifications\/Qualifications :/gs){
print SYNTHESE '//'."$1";
}
else{
print SYNTHESE '//'."N.C.";
}
if (/Certifications\/Qualifications :(.*?)Site web :/gs){
print SYNTHESE '//'."$1\n";
}
else{
print SYNTHESE '//'."N.C.\n";
}
}
close(DETAIL_SOCIETE);
}
close(SYNTHESE);
close(LISTE_SOCIETE); |
Partager