Bon finalement je suis passé à CDP , car certains scripts javascript sur ZeTurf ne tournent pas avec Internet Explorer.
En pièce jointe, un classeur qui contient les classes CDP et un code qui normalement va chercher toutes les informations que tu veux extraire, en utilisant Edge comme navigateur. Voici le code :
Sub ExtractZeturfData(url As String)
10 On Error GoTo ErrHandler
30 Dim objBrowser As CDPBrowser
40 Dim ArrCourse As CDPElement, ArrDetails As CDPElement
50 Dim PariTabs As CDPElement, ArrTabs As CDPElement
60 Dim Rows As Object, Row As CDPElement
70 Dim NomCourse$, LieuCourse$, HeureCourse$, Reunion$, Course$
80 Dim Numero$, NomCheval$, CoteSG$, Place$, parts() As String
90 Dim node As CDPElement
110 Set objBrowser = New CDPBrowser
120 objBrowser.start "edge", cleanActive:=True, reAttach:=True, _
addArgs:="--user-data-dir=d:\CDP\Edge"
' objBrowser.Hide ' on peut cacher le navigateur
130 objBrowser.navigate url, isInteractive
' ============================
' BLOC ARRIVEE-COURSE
' ============================
140 Set ArrCourse = objBrowser.getElementByQuery("#arrivee-course")
150 If ArrCourse Is Nothing Then Err.Raise 1001, , "#arrivee-course introuvable"
160 Reunion = CleanText(ArrCourse.getElementByQuery(".numero-reunion").innerText)
170 Course = CleanText(ArrCourse.getElementByQuery(".numero-course").innerText)
180 LieuCourse = CleanText(ArrCourse.getElementByQuery(".nom-hippodrome-et-drapeau").innerText)
190 parts = Split(CleanText(ArrCourse.getElementByQuery("h1").innerText), " ")
200 DateCourse = parts(UBound(parts))
210 Set ArrDetails = objBrowser.getElementByQuery("#arriveeDetails")
220 If ArrDetails Is Nothing Then Err.Raise 1002, , "#arriveeDetails introuvable"
230 NomCourse = Trim(ArrDetails.getElementByQuery(".nom-course").innerText)
240 HeureCourse = Trim(ArrDetails.getElementByQuery(".heure-course").innerText)
' ============================
' TABLEAU DES PARTANTS
' ============================
250 Set PariTabs = objBrowser.getElementByQuery("#pariCotesTab tbody")
260 If PariTabs Is Nothing Then Err.Raise 1003, , "#pariCotesTab tbody introuvable"
270 Set Rows = objBrowser.getElementsByQuery("#pariCotesTab tbody tr[data-runner]")
280 Debug.Print "Date", "Heure", "Lieu", "Nom Course", "Participants", "Code"
290 Debug.Print "-------------------------------------------------------"
300 Debug.Print DateCourse, HeureCourse, LieuCourse, NomCourse, CStr(Rows.Count), Reunion + Course
Debug.Print "================================================================"
310 Debug.Print "Numéro", "Nom", "Cote SG Live"
320 Debug.Print "-------------------------------------------"
330 For Each Row In Rows
340 Numero = CleanText(Row.getElementByQuery(".partant").innerText)
350 NomCheval = CleanText(Row.getElementByQuery(".cheval a").innerText)
360 Set node = Row.getElementByQuery(".cote")
370 If Not node Is Nothing Then
380 CoteSG = CleanText(node.innerText)
390 Else
400 CoteSG = ""
410 End If
420 Debug.Print Numero, NomCheval, CoteSG
430 Next Row
440 Debug.Print "===================================="
' ============================
' TABLEAU DES ARRIVANTS
' ============================
450 Set ArrTabs = objBrowser.getElementByQuery("#arriveeTab tbody")
460 If ArrTabs Is Nothing Then Err.Raise 1004, , "#arriveeTab tbody introuvable"
470 Set Rows = objBrowser.getElementsByQuery("#arriveeTab tbody tr[data-runner]")
480 Debug.Print "Place", "Numéro"
490 Debug.Print "---------------------"
500 For Each Row In Rows
510 Place = Trim(Row.getElementByQuery("td:nth-child(1)").innerText)
520 Numero = Trim(Row.getElementByQuery(".numero-cheval-card").innerText)
530 Debug.Print Place, Numero
540 Next Row
Debug.Print ("========================================")
550 objBrowser.quit
560 Set objBrowser = Nothing
570 Exit Sub
ErrHandler:
580 Debug.Print "Erreur ligne " & Erl & " - " & Err.Number & " : " & Err.Description
590 On Error Resume Next
600 If Not objBrowser Is Nothing Then objBrowser.quit
610 Set objBrowser = Nothing
End Sub
Attention le paramètres: addArgs:="--user-data-dir=d:\CDP\Edge" est important : il faut définir un répertoire dans lequel on peut écrire et qui en fait stockera les cookies, le cache etc du navigateur pour son utilisation en VBA. Sans ce paramètre on va avoir à chaque fois une fenêtre bloquante accepter les cookies sur le site visité.
voici le code pour balayer toutes les adresses URL de la feuille URLs :
Sub ProcessAllURLs()
10 On Error GoTo ErrHandler
20 Dim ws As Worksheet, lastRow As Long, i As Long, url As String
50 Set ws = ThisWorkbook.Worksheets("URLs")
60 lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
70 For i = 1 To lastRow
80 url = Trim(ws.Cells(i, "A").value)
90 If url <> "" Then
100 Debug.Print "Traitement de : "; url
110 ExtractZeturfData url
120 End If
130 Next i
140 Exit Sub
ErrHandler:
150 Debug.Print "Erreur ProcessAllURLs ligne " & Erl & " - " & Err.Number & " : " & Err.Description
End Sub
Voici ce que j'obtiens pour la première adresse URL de la feuille URLs :
Date Heure Lieu Nom Course Participants Code
-------------------------------------------------------
01/01/2026 10h15 SHA TIN Chuk Yuen Handicap 14 R5C10
================================================================
Numéro Nom Cote SG Live
-------------------------------------------
1 BEAUTY ALLIANCE 15.3
2 NATURAL NUMBERS 18.2
3 SIX PACK 5.2
4 CLASS 36.8
5 KA YING ATTACK 12.1
6 CHARMING LEGEND 34.9
7 GUMMY GUMMY 49.1
8 KEEN MOLLY 19.4
9 WITH A SMILE 2.0
10 ARMOR GOLDEN EAGLE 20.0
11 GHORGAN 21.3
12 LUCKY TOGETHER 49.7
13 EIGHTY LIGHT YEARS 12.7
14 VERY GRATEFUL 55.2
====================================
Place Numéro
---------------------
1er 3
2e 5
3e 11
4e 9
Je me permet de poster ces codes car dans les CGU de zeTurf, il n'y a pas d'interdiction de récupérer des données sur le site. Si quelqu'un voit quelque chose ?
J'espère que cela fonctionne avec Excel 2010, moi j'ai testé en Excel 2021 64 bits , mais normalement les classes CDP sont compatibles avec les Excel 32 bits.
Avec PowerQuery, cela me semble difficile à faire car toutes les informations demandées ne sont pas dans des tables..Ami calmant, J.P