I am trying to do some web scraping in Excel VBA. Here is the part of the code that I am having trouble with:
IE.Navigate URL
Do
DoEvents
Loop While IE.ReadyState <> 4 Or IE.Busy = True
Set doc = IE.document
After running this doc contains html that still has unexecuted JavasScript in it.
This is the signature of the script that has not been executed:
goosSearchPage.Initialize(...)...;
I can wait for execution by doing Application.Wait(Now + TimeValue(x)) but that really is not satisfactory, as the amount of time the script takes to execute is quite variable depending on input.
Is there a way to either wait for the script to finish evaluating or to just evaluate the script directly in the doc object?
解决方案
You actually can evaluate the javascript function with the ie window. But you gotta set up a Callback because the function will be evaluated async.