I'm attempting to use HTTP requests using https://codingislove.com/parse-html-in-excel-vba/ as a guide in order to bypass having to use internet explorer. When I use the following macro it doesn't assign T_Object_S to do anything and skips over the for loop.
Desired url: https://www.theice.com/publicdocs/futures/COTHist2019.csv
The code below does the same thing and with the correct result but uses internet explorer.
The targeted link:
https://www.dropbox.com/s/8fy4rytokppfozs/Untitled.png?dl=0
Desired url: https://www.theice.com/publicdocs/futures/COTHist2019.csv
Code:
SUB Get_File_URL()
Dim oStrm As Object, WinHttpReq As Object, T_Object_S As Object, html As New HTMLDocument, Extension As String, File_Name As String, TitleEM As Object, T_Object As HTMLHtmlElement
File= "https://www.theice.com/marketdata/reports/122"
Set WinHttpReq = CreateObject("MSXML2.XMLHTTP")
WinHttpReq.Open "GET", File, False
WinHttpReq.send
html.body.innerHTML = WinHttpReq.responseText: Set T_Object_S = html.getElementsByClassName("document-list")
For Each T_Object In T_Object_S
TitleEM = T_Object.getElementsByTagName("li")(0)
MsgBox TitleEM.getElementsByTagName("a")(0).innerText
Next T_Object
End SUB
The code below does the same thing and with the correct result but uses internet explorer.
Code:
Sub Scrape_Web_ICE()
Dim internet As Object
Dim internetdata As Object
Dim div_result As Object
Dim header_links As Object
Dim link As Object
Dim URL As String
Set internet = CreateObject("InternetExplorer.Application")
internet.Visible = True
URL = "https://www.theice.com/marketdata/reports/122"
internet.Navigate URL
Do Until internet.ReadyState >= 4
DoEvents
Loop
Application.Wait Now + TimeSerial(0, 0, 5)
Set internetdata = internet.document
Set div_result = internetdata.getElementsByClassName("true-grid-3")
msgbox div_result.Item(1).all.Item(1).FirstChild.NextSibling.all.Item(0).href
internet.Quit
End Sub
https://www.dropbox.com/s/8fy4rytokppfozs/Untitled.png?dl=0
Last edited: