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 99 100 101 102 103 104 105 106 107 108 109 110
| Option Explicit
Sub ListerBalise()
Dim IE As New InternetExplorer
Dim IEdoc As HTMLDocument
Dim htmlTagDate() As IHTMLElement
Dim htmlTagMedia() As IHTMLElement
Dim Generic As HTMLGenericElement
Dim htmlImg As htmlImg
Dim hDiv As HTMLDivElement
Dim i As Integer
'Ouvre la page WEB
IE.navigate "http://www.nrj12.fr/nrj12-replay-3276/nrj-12-562/collectionvideo/922-stargate-atlantis.html"
IE.Visible = True
WaitIE IE
Set IEdoc = IE.document
'On recupere l'element contenant le tableau de vignettes
htmlTagDate = getElementsByClassName(IEdoc.body, "date", False)
htmlTagMedia = getElementsByClassName(IEdoc.body, "media", False)
'On boucle sur les element contenu dans le tableau
For i = 0 To UBound(htmlTagDate) - 1
'On recupere la date
Debug.Print htmlTagDate(i).innerText
'On sauvegarde l'image
SaveHtmlFile htmlTagMedia(i).all(1).href, "D:\MiniPicto\" & htmlTagMedia(i).all(1).nameProp
Next
Set IE = Nothing
Set IEdoc = Nothing
End Sub
Sub SaveHtmlFile(aUrl As String, aDestination As String)
'Pris sur le forum de la msdn (avec quelques menues modifs)
Dim WinHttpReq As Object, oStream As Object
Dim TheURL As String
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", aUrl, False
WinHttpReq.send
TheURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile aDestination
oStream.Close
End If
End Sub
Function getElementsByClassName(IeParentElement As IHTMLElement, ClassName As String, DansSousElement As Boolean) As IHTMLElement()
'Fonction perso, attention par contre je ne l'ai pas encore bien finalisé ^^
'Ne pas utiliser le mode DansSousElement à True, il bug
Dim aElement As IHTMLElement
Dim SousElements() As IHTMLElement
Dim FuncElements() As IHTMLElement
Dim iElem As Integer, iElemS As Integer
Dim Tmpi As Integer
DansSousElement = False
For Each aElement In IeParentElement.all
'On pointe notre tableau de retour
FuncElements = getElementsByClassName
If ClassName = aElement.ClassName Then
If IsArray(FuncElements) Then
Tmpi = UBound(FuncElements) + 1
Else
Tmpi = -1
End If
ReDim Preserve FuncElements(Tmpi)
Set FuncElements(Tmpi) = aElement
End If
If DansSousElement Then
'On recherche dans les sous element
SousElements = getElementsByClassName(aElement, ClassName, False)
'Si on a des element retourné, on les rajoute au tableau precedent
If IsArray(SousElements) Then Tmpi = UBound(SousElements)
If Tmpi > -1 Then
If IsArray(FuncElements) Then Tmpi = UBound(FuncElements) + Tmpi + 2
If (Tmpi > 0) Then
ReDim Preserve FuncElements(Tmpi - 1)
iElemS = UBound(FuncElements) - UBound(SousElements) ' - 1
For iElem = iElemS To UBound(FuncElements)
Set FuncElements(iElem) = SousElements(iElem - iElemS)
Next
End If
End If
End If
getElementsByClassName = FuncElements
Erase SousElements
Next
Erase FuncElements
End Function
Sub WaitIE(IE As InternetExplorer)
'On boucle tant que la page n'est pas totalement chargé
Do Until IE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
End Sub |
Partager