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
| Option Explicit
Sub test_Alsaeco_Com()
cherche_societe , , , , , , 67, "7112B" ' entre chaque virgule vont les données correspondant au argument de la fonction cherche dans le meme ordre
End Sub
Function cherche_societe(Optional raison As String = "", Optional siret As String = "", Optional siren As String = "", Optional nom_dirigant As String = "", Optional prenom_dirigant As String = "", Optional commune As String = "", Optional departement As String = "", Optional ape As String = "")
'Déclaration des variables
Dim IE As New InternetExplorer ' Penser à activer les références « Microsoft Internet Controls » et « Microsoft HTML Object Library » (menu Outils -> Références dans VBA)
Dim IEDoc As HTMLDocument
Dim elem As HTMLUListElement
Dim mon_elem As HTMLUListElement
Dim URL As String
Dim tabURL() As String
Dim htmlTagCol As IHTMLElementCollection
Dim HtmlElementStandard As HTMLGenericElement
Dim i As Integer
'Initialisation des variables
URL = "http://www.alsaeco.com/entreprises/recherche.html?aeadirectoryParam[raison]=" & raison & "&aeadirectoryParam[siret]=" & siret & "&aeadirectoryParam[siren]=" & siren & "&aeadirectoryParam[commune]=" & commune & "&aeadirectoryParam[departement]=" & departement & "&aeadirectoryParam[dirigeant]=" & nom_dirigant & "&aeadirectoryParam[ape]=" & ape & "&aeadirectoryParam[submit]=Rechercher&aeadirectoryParam[page]=8"
'Accès au site web
IE.Navigate URL
IE.Visible = True 'Affichage de la fenêtre IE
WaitIE IE 'On attend le chargement complet de la page
Set IEDoc = IE.document 'On pointe le membre Document (une variable spécifique pour cette élément permet de bénéficier de l'autocomplétion)
'Les entreprises sont listées dans le tableau démarrant à la balise "ul" avec pour classname "coin-plie"
For Each elem In IEDoc.all 'On liste les éléments de ce tableau
If elem.className = "coin-plie" Then
Set mon_elem = elem
Exit For
End If
Next
Set htmlTagCol = mon_elem.getElementsByTagName("a") 'On liste les éléments de type anchor
ReDim tabURL(htmlTagCol.Length, 1)
For i = 0 To htmlTagCol.Length - 1 'On crée un tableau contenant l'ensemble des URL vers les fiches de chaque entreprise
tabURL(i) = htmlTagCol(i).href
MsgBox i & "-" & tabURL(i)
Next
MsgBox "Scan terminé"
'Libération des variables
Set IE = Nothing
Set IEDoc = Nothing
End Function
Sub WaitIE(IE As InternetExplorer)
'On boucle tant que la page n'est pas totalement chargée
Do Until IE.readyState = READYSTATE_COMPLETE 'Ou : IE.readyState = 4
DoEvents
Loop
End Sub |
Partager