I'm experienced with VBA but really new with webscraping. So far I managed to extract some tables from other webpages but this one is giving me a hard time. The link is http://www.banxico.org.mx/SieInternet/consultarDirectorioInternetAction.do?sector=6&accion=consultarCuadro&idCuadro=CF102&locale=es
Basically, I click the arrow drop down list next to "Exportar Cuadro" button. After that, I need to change both dates that appear there to a specific one I will have into a variable.
How can I get to change that input boxes on webpage? My code so far is the next one:
Option Explicit
Sub test()
Dim URL As String, URL2 As String, URL3 As String, URL4 As String
Dim IE As Object, obj As Object, colTR As Object, doc As Object, tr As Object
Dim eleColtr As MSHTML.IHTMLElementCollection 'Element collection for tr tags
Dim eleColtd As MSHTML.IHTMLElementCollection 'Element collection for td tags
Dim eleRow As MSHTML.IHTMLElement 'Row elements
Dim eleCol As MSHTML.IHTMLElement 'Column elements
Dim objCollection As Object
Dim j As String, i As Integer
URL = "https://www.banxico.org.mx/SieInternet/consultarDirectorioInternetAction.do?sector=18&accion=consultarCuadroAnalitico&idCuadro=CA51&locale=es"
URL2 = "https://www.banxico.org.mx/SieInternet/consultarDirectorioInternetAction.do?sector=18&accion=consultarCuadroAnalitico&idCuadro=CA52&locale=es"
URL3 = "https://www.banxico.org.mx/SieInternet/consultarDirectorioInternetAction.do?sector=18&accion=consultarCuadroAnalitico&idCuadro=CA53&locale=es"
URL4 = "http://www.banxico.org.mx/SieInternet/consultarDirectorioInternetAction.do?sector=6&accion=consultarCuadro&idCuadro=CF102&locale=es"
'Tipos de cambio
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate URL4
Do While IE.Busy Or IE.readyState <> 4
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:01"))
IE.document.getElementById("exportaCuadroToggle").Click
Set objCollection = IE.document.getElementsByTagName("ID")
i = 0
While i < objCollection.Length
If objCollection(i).Value = "26/08/2019" Then
' Set text for search
objCollection(i).Value = "01/08/2019"
End If
If objCollection(i).Name = "form-control form-control-sm fechaFin" Then
' Set text for search
objCollection(i).Value = "01/08/2019"
End If
Wend
End Sub
Note: URL
, URL2
and URL3
are used in the complete code but I ommited that part for now because those links are already doing what I want.