getElementsByClassName & getElementsByTagName
Publicado por SANCHEZ CASTELLO, S.L. (14 intervenciones) el 28/01/2019 19:17:46
Hola,
Estoy tratando de extraer un dato de una web que tiene el código que he adjuntado. El dato en particular que quiero incorporar a excel esta recogido en esta sección (en la imagen adjunta aparece subrayado y el dato buscado sería "33"):
1
<span class="value--2NhHD">33</span>
Este es el código VBA que hasta el momento estoy desarrollando y del que no se aplicar getElementsByClassName / getElementsByTagName para conseguir el dato que estoy buscando:
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
Private Sub ExtraerDato()
Dim i As Long
Dim ie As Object
Dim objElement As Object
Dim objCollection As Object
'dimension (declare or set aside memory for) our variables
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
Dim y As Integer 'integer variable we'll use as a counter
Dim result As String 'string variable that will hold our result link
Dim Web As String
Dim objCollection As Object
Web= Sheets("Hoja1").Range("A1")
'initiating a new instance of Internet Explorer and asigning it to objIE
Set objIE = New InternetExplorer
'make IE browser visible (False would allow IE to run in the background)
objIE.Visible = True
'navigate IE
objIE.navigate Web
'wait here a few seconds while the browser is busy
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
'Begin extraction
Set objCollection = objIE.document.getElementsByClassName("container")
Sheets("Hoja1").Range("A2") = objCollection.getElementsByTagName("span")(0).innerText
End Sub
Gracias de antemano por vuestra ayuda.
Saludos
Valora esta pregunta
0