Option Explicit
Public Url As String
Sub test()
Dim lescourses, t$, Url$, tbl
Url = "http://simple.gagnant.place.free.fr/page6.html"
lescourses = GetDatacourse(Url)
Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(lescourses), 7) = lescourses
End Sub
Function GetDatacourse(Url)
Dim REQ, co(), code$, d, q&
Dim matableRalye, elem, mesBalisesP, P
Set REQ = CreateObject("microsoft.xmlhttp")
With REQ: .Open "GET", Url, False: .send: code = .responsetext: End With
With CreateObject("htmlfile")
.body.innerhtml = code
For Each elem In .all
If elem.className = "FicheTabIntChapo" Then
Set matableRalye = elem
q = q + 1
ReDim Preserve co(1 To 8, 1 To q)
Set mesBalisesP = matableRalye.getElementsByTagName("P")
'For Each P In mesBalisesP: MsgBox P.innerText: Next
co(8, q) = matableRalye.innerText '.TextComplet
co(2, q) = Split(Split(mesBalisesP(1).innerText, "- ")(2), " ")(0) '.partants
co(3, q) = Val(Replace(Split(mesBalisesP(2).innerText, " -")(0), ".", "")) '.Prix
co(4, q) = "Gr" '.Category
If InStr(1, mesBalisesP(2).innerText, "Course ") > 0 Then co(4, q) = Split(Split(mesBalisesP(2).innerText, "Course ")(UBound(Split(mesBalisesP(2).innerText, "Course "))), ",")(0)
d = Split(mesBalisesP(mesBalisesP.Length - 1).innerText, " -")(0)
co(5, q) = DateValue(Replace(d, Split(d, " ")(0), "")) '.DateX
co(1, q) = Split(mesBalisesP(mesBalisesP.Length - 1).innerText, " -")(1) '.Lieu
co(6, q) = Split(mesBalisesP(2).innerText, " -")(1) '.sexeCategory
co(7, q) = Val(Trim(Split(mesBalisesP(1).innerText, "-")(1))) '.Distance
End If
Next
End With
GetDatacourse = Application.Transpose(co)
End Function