Jump to content

error $olink.href


Recommended Posts

Hello everybody,

I have a problem with a loop. Aparently, it's the StringInStr function, but I don't understand why...

If StringInStr($oLink.href, "http://www.aef.cci.fr/accueil/listeEntreprises/ficheEntreprise?siret=" & $Extraction_siret) Then
If StringInStr($oLink.href^ ERROR

My complete script :

#include <IE.au3>
#include <Array.au3>
#include <File.au3>
#Include <String.au3>

$Page_internet = _IECreate("http://www.aef.cci.fr/", 0, 1, 1)

$Fichier_sirets = FileOpen(@MyDocumentsDir & "\Sirets_SL.txt", 0)

If $Fichier_sirets = -1 Then
    Exit
EndIf

While 1
    $Ligne_sirets = FileReadLine($Fichier_sirets)
    If @error = -1 Then ExitLoop
    $Extraction_siret = StringTrimLeft($Ligne_sirets, 8)

    _IENavigate($Page_internet, "http://www.aef.cci.fr/")
    _IELoadWait($Page_internet)
    Sleep(400)

    $Case_raison_sociale = _IEGetObjById($Page_internet, "label")
    $Case_SIREN_SIRET = _IEGetObjById($Page_internet, "identifiant")
    $Case_nom = _IEGetObjById($Page_internet, "nom")
    $Case_departement = _IEGetObjById($Page_internet, "dep")

    _IEPropertySet($Case_raison_sociale, "innertext", "")
    _IEPropertySet($Case_SIREN_SIRET, "innertext", $Extraction_siret)
    _IEPropertySet($Case_nom, "innertext", "")
    _IEPropertySet($Case_departement, "innertext", "")

    $Bouton_Rechercher = _IEGetObjById($Page_internet, "valider")
    _IEAction($Bouton_Rechercher, "click")
    _IELoadWait($Page_internet)

    $oLinks = _IELinkGetCollection($Page_internet)
    For $oLink In $oLinks
        If StringInStr($oLink.href, "http://www.aef.cci.fr/accueil/listeEntreprises/ficheEntreprise?siret=" & $Extraction_siret) Then
            _IEAction($oLink, "click")
            _IELoadWait($Page_internet)
            Sleep(400)

            $Contenu = _IEBodyReadHTML($Page_internet)
            ConsoleWrite($Contenu & @CRLF)

            $aHold = StringRegExp($Contenu, "(?i)(?s).+?Identité.+?(<dl.+/dl>)", 1)
            If NOT @Error Then
                $aHold = StringRegExp($aHold[0], "(?i)<dt>(Siret|Effectif|voie|Code postal|Ville|Téléphone|Forme juridique|Activité en clair)\s*</dt>\s*<dd>(.+)</dd>", 3)
                If NOT @Error Then
                    $sRtn = ""
                    For $i = 0 To UBound($aHold) -2 Step 2
                        $sRtn &= $aHold[$i] & " : " & $aHold[$i +1] & @CRLF
                    Next
                    FileWriteLine(@MyDocumentsDir & "\Coordonnees_entreprises_SL.txt", $sRtn & @CRLF)
;~                  ConsoleWrite($sRtn & @CRLF)
                EndIf
            EndIf
        EndIf
    Next
    MsgBox(0, "","YES")
Wend

FileClose($Fichier_sirets)

Thanks

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

If you click on a link or _IENavigate() away from the current page the collection $oLinks becomes invalid. It fails when it comes back through the loop and you try $oLink.href again after the collection is invalid.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

If you click on a link or _IENavigate() away from the current page the collection $oLinks becomes invalid. It fails when it comes back through the loop and you try $oLink.href again after the collection is invalid.

:(

I am resolving the problem. I have putting the loop in a function !

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...