#!/bin/bash # nécéssaire pour traiter les URL en arabe urldecode() { local u="${1//+/ }"; printf '%b' "${u//%/\\x}"; } # nettoyer le dossier en supprimant le tableau préexistant rm -f "$2/tableau.html" ; # Les deux arguments marquent les dossiers des URL et du Tableau echo "Les urls SONT DANS : $1" ; echo "On créé le tableau HTML dans : $2" ; echo "TABLEAU D'URLs" >> "$2/tableau.html"; # Compteur numerotableau=1; motif=$3; for fichier in $(ls $1) do compteur=1; echo "$1/$fichier" ; #Créer le tableau echo "" >> "$2/tableau.html" ; echo "" >> "$2/tableau.html" ; #Traitement liens for ligne in $(cat "$1/$fichier") do echo "----------------------------------------------"; echo "Traitement de l'URL : $ligne"; echo "----------------------------------------------"; # Convertir les liens en lettres arabes si nécéssaire ligne=$(urldecode $ligne) ligne=$(urldecode $ligne) # Tester la connection aux URLS et récupération du HTTP Code coderetourhttp=$(curl -SIL -o tmp.txt -w %{http_code} $ligne); echo "CODE HTTP : $coderetourhttp"; if [[ $coderetourhttp == 200 ]] then echo "CODE HTTP OK" curl -sL -o "./PAGES-ASPIREES/$numerotableau-$compteur.html" "$ligne"; #gérer les fichiers compressés if [[ $(file -b --mime-type "./PAGES-ASPIREES/$numerotableau-$compteur.html" | egrep "zip") != "" ]] then echo "compressé" mv "./PAGES-ASPIREES/$numerotableau-$compteur.html" "./PAGES-ASPIREES/$numerotableau-$compteur.gz"; gunzip -c "./PAGES-ASPIREES/$numerotableau-$compteur.gz" > "./PAGES-ASPIREES/$numerotableau-$compteur.html"; rm "./PAGES-ASPIREES/$numerotableau-$compteur.gz"; fi encodage=$(curl -sIL -o toto -w %{content_type} $ligne | cut -f2 -d"=" | tr '[a-z]' '[A-Z]' | tr -d '\r' | tr -d '\n' ); if [[ $encodage == "UTF-8" ]] then echo "ENCODAGE UTF-8 OK" # Utilise lynx sur la page aspirée pour créer le dump lynx -dump -nolist -assume_charset=$encodage -display_charset=$encodage "./PAGES-ASPIREES/$numerotableau-$compteur.html" > ./DUMP-TEXT/$numerotableau-$compteur.txt; # Et puis on utilise egrep pour créer les contextes egrep -i -C2 "$motif" ./DUMP-TEXT/$numerotableau-$compteur.txt > ./CONTEXTES/$numerotableau-$compteur.txt; # Fréquence du motif nbmotif=$(egrep -coi "$motif" ./DUMP-TEXT/$numerotableau-$compteur.txt); # Contexte HTML perl ./MINIGREP/minigrepmultilingue.pl "UTF-8" ./DUMP-TEXT/$numerotableau-$compteur.txt ./MINIGREP/motif-regexp.txt ; mv resultat-extraction.html ./CONTEXTES/$numerotableau-$compteur.html ; # Index egrep -o "\w+" ./DUMP-TEXT/$numerotableau-$compteur.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/index-$numerotableau-$compteur.txt; # Créer bitextes egrep -o "\w+" ./DUMP-TEXT/$numerotableau-$compteur.txt > bi1.txt; tail -n +2 bi1.txt > bi2.txt ; paste bi1.txt bi2.txt > bi3.txt ; cat bi3.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/bigramme-$numerotableau-$compteur.txt ; # Remplir le tableau echo "" >> "$2/tableau.html"; # Pour les pages qui ne sont pas en UTF8 else echo "---------Récupération des URLs qui ne sont pas en UTF8. ENCODAGE initial est <$encodage>------" if [[ $encodage != "" ]] echo "RECUPERATION DE L'ENCODAGE" then #charset encodagefile=$(egrep -oi "charset=\"?[^\"&,)]+\"?" ./PAGES-ASPIREES/$numerotableau-$compteur.html | cut -d"=" -f2 | head -1| tr '[a-z]' '[A-Z]' | tr -d '\r' | tr -d '"' ); # on répète les mêmes opérations si l'encodage est en UTF-8 if [[ $encodagefile == "UTF-8" ]] then echo "ENCODAGE UTF-8 OK" # on fait le dump lynx -dump -nolist -assume_charset=$encodagefile -display_charset=$encodagefile "./PAGES-ASPIREES/$numerotableau-$compteur.html" > ./DUMP-TEXT/$numerotableau-$compteur.txt; # Contexte egrep -i -C2 "$motif" ./DUMP-TEXT/$numerotableau-$compteur.txt > ./CONTEXTES/$numerotableau-$compteur.txt; #Fréquence motif nbmotif=$(egrep -coi "$motif" ./DUMP-TEXT/$numerotableau-$compteur.txt); #Contexte HTML perl ./MINIGREP/minigrepmultilingue.pl "UTF-8" ./DUMP-TEXT/$numerotableau-$compteur.txt ./MINIGREP/motif-regexp.txt ; mv resultat-extraction.html ./CONTEXTES/$numerotableau-$compteur.html ; #Index egrep -o "\w+" ./DUMP-TEXT/$numerotableau-$compteur.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/index-$numerotableau-$compteur.txt #Bitexte egrep -o "\w+" ./DUMP-TEXT/$numerotableau-$compteur.txt > bi1.txt; tail -n +2 bi1.txt > bi2.txt ; paste bi1.txt bi2.txt > bi3.txt ; cat bi3.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/bigramme-$numerotableau-$compteur.txt ; #Et on remplit le tableau avec echo " " >> "$2/tableau.html" ; #on utilise iconv sur les encodages qui ne sont pas reconnus else reponse=$(iconv -l | egrep -i $encodagefile) if [[ $reponse != "" ]] # encodage reconnu! echo "Encodage reconnu!" then #faire deux dump séparés avec lynx et iconv lynx -dump -nolist -assume_charset=$encodagefile -display_charset=$encodagefile "./PAGES-ASPIREES/$numerotableau-$compteur.html" > ./DUMP-TEXT/$numerotableau-$compteur-$encodagefile.txt; iconv -c -f $encodagefile -l UTF-8 ./DUMP-TEXT/$numerotableau-$compteur-$encodagefile.txt > ./DUMP-TEXT/$numerotableau-$compteur.txt; #Contexte egrep -i -C2 "$motif" ./DUMP-TEXT/$numerotableau-$compteur.txt > ./CONTEXTES/$numerotableau-$compteur.txt; #Fréquence nbmotif=$(egrep -coi "$motif" ./DUMP-TEXT/$numerotableau-$compteur.txt); #Contexte HTML perl ./MINIGREP/minigrepmultilingue.pl "UTF-8" ./DUMP-TEXT/$numerotableau-$compteur.txt ./MINIGREP/motif-regexp.txt ; mv resultat-extraction.html ./CONTEXTES/$numerotableau-$compteur.html ; # Indexe egrep -o "\w+" ./DUMP-TEXT/$numerotableau-$compteur.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/index-$numerotableau-$compteur.txt # Bitextes egrep -o "\w+" ./DUMP-TEXT/$numerotableau-$compteur.txt > bi1.txt; tail -n +2 bi1.txt > bi2.txt ; paste bi1.txt bi2.txt > bi3.txt ; cat bi3.txt | sort | uniq -c | sort -r > ./DUMP-TEXT/bigramme-$numerotableau-$compteur.txt ; echo "" >> "$2/tableau.html"; #On réserve cette section pour les URLS qui ne peuvent pas être traités else echo " " >> "$2/tableau.html"; fi fi fi fi fi compteur=$((compteur+1)); done echo "
URLCode HTTPEncodagePage aspiréeDumpFiltrage TexteFiltrage HtmlIndexBitexteFréquence Motif
$compteur Lien n° $compteur $coderetourhttp $encodage $numerotableau-$compteur.html $numerotableau-$compteur.txt $numerotableau-$compteur.txt $numerotableau-$compteur.html index-$numerotableau-$compteur.txt bigramme-$numerotableau-$compteur.txt $nbmotif
$compteur Lien n° $compteur $coderetourhttp $encodagefile $numerotableau-$compteur.html $numerotableau-$compteur.txt $numerotableau-$compteur.txt $numerotableau-$compteur.html index-$numerotableau-$compteur.txt bigramme-$numerotableau-$compteur.txt $nbmotif
$compteur Lien n° $compteur $coderetourhttp $encodagefile => UTF-8 $numerotableau-$compteur.html $numerotableau-$compteur.txt $numerotableau-$compteur.txt $numerotableau-$compteur.html index-$numerotableau-$compteur.txt bigramme-$numerotableau-$compteur.txt $nbmotif
$compteur Lien n° $compteur $coderetourhttp - - - - - - - -

" >> "$2/tableau.html"; numerotableau=$((numerotableau+1)); done echo "" >> "$2/tableau.html";