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
| Option Explicit
Sub RechercheVBAExcel()
Dim sLogin, elem, bankpage, nombredepage, repere1, repere, boutonsuiv, pag
Sheets(1).Cells.Clear
'Déclaration des variables
Dim IE As Object, IEDoc As Object, deb, gate As Date, code
Set IE = CreateObject("internetexplorer.application")
'Chargement de la page cdm
IE.navigate "https://www.cdmparis.net/CDG/Pages/Liste-vols-arrivee.aspx"
IE.Visible = True
Do: DoEvents: Loop While IE.readyState <> 4 Or IE.Busy ' on laisse travailler IE
Set IEDoc = IE.document
' si on fait deux fois de suite la manoeuvre la 2d fois on est deja connecté
On Error GoTo nologin
Set sLogin = IEDoc.getElementById("ctl00_ContentPlaceHolder1_UsernameTextBox")
If Not sLogin Is Nothing Then
IEDoc.getElementById("ctl00_ContentPlaceHolder1_UsernameTextBox").Value = "regultrafic-cdg1@geh.aero" 'login mail
IEDoc.getElementById("ctl00_ContentPlaceHolder1_PasswordTextBox").Value = "Pcat1cdm" 'PASSSEWORD
IEDoc.getElementById("ctl00$ContentPlaceHolder1$SubmitButton").Click
End If
nologin:
Do: DoEvents: Loop While IE.readyState <> 4 Or IE.Busy ' on laisse travailler IE
With IEDoc
'POUR LE " Terminal"
.getElementsByName("ctl00$m$g_31a5f278_281c_49b2_a0c0_f8ec15187b13$ctl00$rgVols$ctl00$ctl02$ctl02$FilterTextBox_Terminal")(0).Value = "C1"
' il faut que le menu soit present et affiché sinon le bouton "Contient" de la fausse combo n'existe pas car il est dynamique alors on clique sur la fleche
.all("ctl00$m$g_31a5f278_281c_49b2_a0c0_f8ec15187b13$ctl00$rgVols$ctl00$ctl02$ctl02$Filter_Terminal").Click
'maintenant on choisi l'item "Contient"
For Each elem In .all
If elem.innerText = "Contient" Then elem.Click ' l'action se fait que a ce moment la
Next
Do: DoEvents: Loop While IE.readyState <> 4 Or IE.Busy ' on laisse travailler IE
' la periode
.getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_ddlTo_Input").Value = "HC+18h"
.getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_ddlFrom_Input").Value = "HC+2h"
.getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_btnDisplayPeriod_input").Click
Do: DoEvents: Loop While IE.readyState <> 4 Or IE.Busy ' on laisse travailler IE
' ci dessous on determine le nombre de pages
Set bankpage = IEDoc.getElementsByClassName("rgWrap rgInfoPart")(0)
nombredepage = Val(Trim(Right(Split(bankpage.innerText, ",")(0), 2)))
'msgbox bankpage.innertext & vbcrlf & nombredepage
repere1 = .getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_rgVols_GridData").getElementsByTagName("TABLE")(0).getElementsByTagName("tbody")(2).getElementsByTagName("TR")(10).innerText
' a partir d'ici il faut boucler pour naviger sur les pages
'ci dessous la 1ere page et sa table que tu souhaite recupérer dans chaque page regarde dans le debug
' Debug.Print .getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_rgVols_GridData").getElementsByTagName("TABLE")(0).getElementsByTagName("tbody")(2).innerText
code = code & "<p>page 1</p><table>"
code = code & .getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_rgVols_GridData").getElementsByTagName("TABLE")(0).getElementsByTagName("tbody")(2).innerHTML
code = code & "</TABLE>"
'on determine le bouton page suivante
'For Each elem In .all
' If elem.Title = "Page suivant" Then Set boutonsuiv = elem: Exit For
' Next
Set boutonsuiv = .getElementsByClassName("rgPageNext")(0)
'a partir de la ca ne fonctionne pas
For pag = 1 To nombredepage - 1
boutonsuiv.Click 'bouton page suivante
'Do: DoEvents: Loop While IE.readyState <> 4 Or IE.Busy
Do
repere = .getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_rgVols_GridData").getElementsByTagName("TABLE")(0).getElementsByTagName("tbody")(2).getElementsByTagName("TR")(10).innerText
Loop While repere = repere1
' Debug.Print "page " & pag + 1
' Debug.Print .getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_rgVols_GridData").getElementsByTagName("TABLE")(0).getElementsByTagName("tbody")(2).innerText
code = code & "<p>page " & pag + 1 & "</p><TABLE>"
code = code & .getElementById("ctl00_m_g_31a5f278_281c_49b2_a0c0_f8ec15187b13_ctl00_rgVols_GridData").getElementsByTagName("Table")(0).getElementsByTagName("tbody")(2).innerHTML & "</table> "
code = code & "</TABLE>"
Next
End With
'maintenant on envoie tout ca en html dans le clipboard d'un htmldocument virtuel en memoire pour le paster sur le sheets
With CreateObject("htmlfile")
If .parentWindow.clipboardData.setData("Text", code) Then
' Application.ScreenUpdating = False
With Sheets(1)
.Activate
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
.Paste ' avec tout les elements et links etc....
'.PasteSpecial Format:="Texte", link:=False, DisplayAsIcon:=False ' au format texte
End With
.parentWindow.clipboardData.clearData "Text"
End If
End With
' on a fini alors on quitte IE a la fin
IE.Quit
With ActiveSheet.Columns("A:Ah")
.AutoFit
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
End Sub |