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
| Option Explicit
Dim IE As InternetExplorer 'nécessite d'activer la référence Microsoft Internet Controls
Dim Helem As IHTMLElementCollection 'nécessite d'activer la référence Microsoft HTML Objects Library
Dim AdrsUrl As String
Dim Msg As String
Dim Fini As Long
Private Sub Form_Load()
Command1.Move 60, 120, 1815, 375
Command1.Caption = "Récupérer les Inputs"
Command2.Move 2040, 120, 2715, 375
Command2.Caption = "Go recherche ''Brouette''": Command2.Enabled = False
Text1.Move 60, 540, 8295, 4635
Text1.Text = ""
'Text1.MultiLine = True ' ******** A faire en design ***********
'Text1.ScrollBars = 3 ' ******** A faire en design ***********
Me.Move 0, 0, 8685, 5820
End Sub
Private Sub Form_Unload(Cancel As Integer)
If TypeName(IE) <> "Nothing" Then Set IE = Nothing
End Sub
Private Sub Command1_Click()
Dim T As Long
AdrsUrl = "http://thyez.e-bricodrive.fr/index.php"
Text1.Text = "En cours de connexion ...../"
Set IE = New InternetExplorer
Fini = Timer + 10
IE.Navigate AdrsUrl
Do While IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
If Timer > Fini Then Me.Caption = "Délais dépassé": Exit Do
If Text1.Text = "En cours de connexion ...../" Then Text1.Text = "En cours de connexion .....\" Else Text1.Text = "En cours de connexion ...../"
Loop
If Me.Caption = "Délais dépassé" Then
Set IE = Nothing
MsgBox "Impossible de ce connecter", vbInformation, "Délais dépassé"
Exit Sub
End If
Set Helem = IE.Document.getElementsByTagName("input")
'boucle pour lister les objets type "input" de la page
'afin d'identifier les champs, les objets Input peuvent être des TextBox ou des boutons
Text1.Text = "Récupération de Inputs .....": Msg = ""
For T = 0 To Helem.length - 1
Msg = Msg & "Élément N°" & CStr(T) & _
" | Nom: " & Helem(T).getAttribute("name") & _
" | Id: " & Helem(T).getAttribute("id") & _
" | Valeur: " & Helem(T).getAttribute("value")
If T <> Helem.length - 1 Then Msg = Msg & vbNewLine
Next T
IE.Visible = True
Text1.Text = Msg
Command2.Enabled = True
Me.SetFocus
End Sub
Private Sub Command2_Click()
'je sais maintenant les noms et/ou les Ids des éléments Input de la page visité
'j'utilise ses informations pour rechercher des brouettes chez ce fournisseur
Msg = "Brouette"
Helem("searchString").innerText = Msg ' je remplis la boite "Trouver un produit..."
Helem("searchStringOk").Click ' je clique sur le bouton "Ok"
DoEvents
'j'ai récupéré l'adresse suite a la réponse donné à la requête
AdrsUrl = "http://thyez.e-bricodrive.fr/produitListe.php?searchString=" & Msg & "&order=PERTINENCE&ok.x=0&ok.y=0"
Fini = Timer + 10
'boucle en attente d'actualisation de la page suivant la requête
Do While IE.LocationURL <> AdrsUrl
DoEvents
If Timer > Fini Then Me.Caption = "Délais dépassé": Exit Do
Loop
If IE.LocationURL <> AdrsUrl Then MsgBox "Problème ?", vbInformation, "Délais dépassé"
'IE.Quit: Set IE = Nothing
End Sub |
Partager