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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| Option Explicit
Dim ValeurIndice As String
'--------------------------------------------- Gestion/manipulation de page internet ---------------------------------
Public Function IeAtt(IeApp As Object, Optional ByVal TempoReadyComplet As Double = 10.5) As Boolean
'Attente d'un chargement complet suite à l'appel d'une page internet
'IeApp: Objet de type InternetExplorer
'TempoReadyComplet: temporisation au delà du quel il est considérée que la connexion à échouée
Dim TpFin As Double
IeAtt = True
TpFin = Timer + TempoReadyComplet
Do While IeApp.readyState <> READYSTATE_COMPLETE
DoEvents
If Timer > TpFin Then IeAtt = False: Exit Do
Loop
End Function
Public Function IeDocAtt(IeApp As Object, Optional ByVal TempoDocLoading As Double = 0.25, Optional ByVal TempoDocComplet As Double = 0.5) As Boolean
'Attente du document suite a une action qui recharge une page internet
'TempoDocLoading: tempo au delà du quel il est considérée que le loading est déjà dépassé
'TempoDocComplet: tempo au delà du quel il est considérée que le document n'est pas récupérable
Dim TpFin As Double
IeDocAtt = True
TpFin = Timer + TempoDocLoading
Do While IeApp.document.readyState <> "loading"
DoEvents
If Timer > TpFin Then IeDocAtt = False: Exit Do
Loop
TpFin = Timer + TempoDocComplet
Do While IeApp.document.readyState <> "complete"
DoEvents
If Timer > TpFin Then IeDocAtt = False: Exit Do
Loop
If IeApp.document.readyState = "complete" Then IeDocAtt = True
End Function
Public Function IeAttUrl(IeApp As Object, AdrsUrlAttendue As String, Optional ByVal TempoComplet As Double = 2.5) As Boolean
'Attente d'une page internet avec verification du bon branchement à une adresse précisée par AdrsUrlAttendue
Dim TpFin As Double
IeAttUrl = True
TpFin = Timer + TempoComplet
Do While IeApp.LocationURL <> AdrsUrlAttendue
DoEvents
If Timer > TpFin Then IeAttUrl = False: Exit Do
Loop
End Function
Private Sub Form_Load()
Dim IE As InternetExplorer
Dim IEDoc As HTMLDocument
Dim DocTbl As HTMLTable
Dim TblCollectionLgn As HTMLTableCell
Dim AdrssUrl As String
Set IE = New InternetExplorer
AdrssUrl = "http://www.insee.fr/fr/bases-de-donnees/bsweb/serie.asp?idbank=001515333"
IE.navigate AdrssUrl
If IeAtt(IE, 5.5) = False Then
MsgBox "Cela ne fonctionne pas", vbCritical, "Zut"
Set IE = Nothing
Exit Sub
End If
If IeAttUrl(IE, AdrssUrl, 2.2) = False Then
MsgBox "vous avez été redirigé sur une autre page" & vbNewLine _
& "Le titre de la page affichée est:" & vbNewLine _
& IE.document.Title, vbCritical, "Pour info"
IE.Quit
Set IE = Nothing
End If
Set IEDoc = IE.document
If IEDoc.Title = "HTTP 500 Erreur interne au serveur" Then
MsgBox "Le document attendue n'est pas present" & vbNewLine _
& "Le titre du document est:" & vbNewLine _
& IEDoc.Title, vbCritical, "Pour info"
Set IEDoc = Nothing
IE.Quit
Set IE = Nothing
End If
'Là on est bien sur la bonne page
'IE.Visible = True
Set DocTbl = IEDoc.All("contenu")
Set TblCollectionLgn = DocTbl.children(5)
Set TblCollectionLgn = TblCollectionLgn.children(1)
Set TblCollectionLgn = TblCollectionLgn.children(1)
Set TblCollectionLgn = TblCollectionLgn.children(2)
ValeurIndice = TblCollectionLgn.innerText
Set TblCollectionLgn = Nothing
Set DocTbl = Nothing
Set IEDoc = Nothing
IE.Quit
Set IE = Nothing
MsgBox "Indice de référence des loyers de l'INSEE : " & ValeurIndice
End Sub |
Partager