http://www.autoitscript.fr/forum/viewto ... =3&t=11063
un exemple basique à base de InetRead et de regexp pour un script de récupération de données sur plusieurs pages d'un site avec stockage des données dans une array
► Afficher le texte
Code : Tout sélectionner
; http://www.journal-officiel.gouv.fr/association/index.php?ctx=eJyLz2FIK2KIL8tjSCwuzk9miC9kSMwsKs5PK1FIzi8qyC9KLEnVLylKTbVSCskvUGKIz8gscSvNyWEwMmUAAG3jE!U_&page=1&WHAT=airsoft"
;==================================================
#Include <Array.au3>
Global $total = 0, $array[1][5]
 ; header pour le _ArrayDisplay (ligne 0)
$array[0][0] = "Annonce N°"      
$array[0][1] = "Date"
$array[0][2] = "Association"
$array[0][3] = "Code postal"
$array[0][4] = "Adresse"
Global $begin = TimerInit()   ; juste pour voir
Global $splash = SplashTextOn (" ", "Démarrage ...  ", 280, 55, -1, -1, 49)
AdlibRegister("_timer", 1000)
$url0 = "http://www.journal-officiel.gouv.fr/association/index.php?ctx=eJyLz2FIK2KIL8tjSCwuzk9miC9kSMwsKs5PK1FIzi8qyC9KLEnVLylKTbVSCskvUGKIz8gscSvNyWEwMmUAAG3jE!U_&page=1&WHAT=airsoft"
$txt0 = BinaryToString(InetRead($url0), 4)
$txt1 = StringRegExp($txt0, '(?s)/\s*(\d{1,3})\s*<', 1)
$nbpages = $txt1[0]     ; récupération sur la page 1 du nb total de pages
For $page = 1 to $nbpages       ; pour chaque page
$url = "http://www.journal-officiel.gouv.fr/association/index.php?ctx=eJyLz2FIK2KIL8tjSCwuzk9miC9kSMwsKs5PK1FIzi8qyC9KLEnVLylKTbVSCskvUGKIz8gscSvNyWEwMmUAAG3jE!U_&page=" & $page & "&WHAT=airsoft"
$txt = BinaryToString(InetRead($url), 4)   ; lecture de la page
$items = StringRegExp($txt, '(?s)<hr/>(.*?)"hr">', 3)    ; récupération du bloc html pour chaque annonce
$n = UBound($items)   ; nb d'annonces présentes sur la page en cours
ReDim $array[$total+$n+1][5]      ; redimensionne l'array à chaque nouvelle page ($total = nb total d'annonces déjà traitées)
For $i = 0 To UBound($items) - 1     ; pour chaque annonce
  $items[$i] = StringReplace($items[$i], " ", " ")
  ; tri et récupération par regex des infos de l'annonce
  $annonce = StringRegExpReplace($items[$i], '(?s).+?(\d+).+', "$1")     ; n° de l'annonce
  $date = StringRegExpReplace($items[$i], '(?s).+Paru le : <b>(.*?)<.+', "$1")    ; date
  $assoc = StringRegExpReplace($items[$i], '(?s).+Association : <b>(.*?)<.+', "$1")   ; nom de l'assoc
  $siege = StringRegExpReplace($items[$i], '(?s).+(?:nouvelle adresse|ge social).+?/i>(.*?)\.\s<i.+', "$1")   ; adresse 
  ; correction des éléments de syntaxe html
  $siege = StringReplace($siege, "è", "è") 
  $siege = StringReplace($siege, "é", "é")  
  $siege = StringReplace($siege, "’", "'")
  $siege = StringReplace($siege, "â", "â")  
  $siege = StringReplace($siege, "ê", "ê") 
  $siege = StringReplace($siege, "î", "î") 
  $siege = StringReplace($siege, "ô", "ô") 
  $siege = StringReplace($siege, "ç", "ç") 
  $siege = StringReplace($siege, "<sup>o</sup>", "°")  
  $siege = StringReplace($siege, "<sup>e</sup>", "e") 
  $siege = StringReplace($siege, "<sup>r</sup>", "r")  
  $siege = StringRegExpReplace($siege, "<i>|</i>", "")  ; etc
  $codepostal = StringRegExpReplace($siege, '.*(\d{5}).+', "$1")   ; code postal
  ; enregistrement dans l'array du contenu de l'annonce
  $array[$total+$i+1][0] = $annonce  
  $array[$total+$i+1][1] = $date
  $array[$total+$i+1][2] = $assoc
  $array[$total+$i+1][3] = $codepostal
  $array[$total+$i+1][4] = $siege
Next
$total += $n   ; actualisation du nb total d'annonces déjà traitées
Next
AdlibUnRegister("_timer")
$message = "Terminé  en  " & _timer()
ControlSetText($splash, "", "Static1", $message)
Sleep(2000)
SplashOff()
Msgbox(0,"", $message)
_ArrayDisplay($array)
;=======================
Func _timer()
  $diff = Round(TimerDiff($begin)/1000) 
  $sec = Mod($diff, 60)
  $min = Mod($diff/60, 60)
 If $diff<60 Then 
  $message = "Chargement ...  " & StringFormat("            %02i sec", $sec)
 Else
  $message = "Chargement ...  " & StringFormat("%02i mn %02i sec", $min, $sec)
 EndIf
  ControlSetText($splash, "", "Static1", $message)
 Return StringFormat("%02i mn %02i sec", $min, $sec)
EndFunc
 

