I've been doing Google detective work for a few hours (including searching StackOverflow) for a technique to allow targeting of HTML elements produced by JavaScript in VBA.
As an example, I cannot use ie.Document.getElementById(id) on this: http://www.kisfutures.com/electronic.html?page=quote&sym=NGU12&mode=i
However, that method is quite capable of finding elements on static pages, as tested on google.com.
I've played with simply getting all the InnerText from Document.body and then parsing the file for my desired TD values, but I ran into a roadblock when trying to split two values that are on different lines. As an illustration, the following was understood by Split(..) as "2040":
20
40
From what I understand, the problem with getElementById(id) is that the website's table is generated by JavaScript after the page has loaded, and thus any elements created by that JavaScript cannot be targeted by my VBA code. Is there anyway to have my VBA code see this JavaScript-generated content?
Thank you for your help!
Edit
The VBA code being used:
Function Quote(Market, Parameter)
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.kisfutures.com/electronic.html?page=quote&sym=NGU12&mode=i"
While ie.Busy
DoEvents
Wend
Dim id As String
id = "dt1_" & Market & "_" & StrConv(Parameter, vbLowerCase)
Quote = ie.Document.getElementByID(id).InnerText
ie.Quit
End Function
Basically I try to build an HTML element ID using the column header for the Market. So if, for example the market is "NGU12" and the column header is "Open", the ID built is: "dt1_NGU12_open", which is the ID for the TD element containing the "Open" value for market NGU12.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…