Back again folks with another question that is plaguing me and I am hoping someone will rescue me once again.
The site that I am trying to scrape from is https://www.poloniex.com/exchange#btc_dgb
The code that I am using is the following:
What I am wanting to do is create some type of runtime error trapping to speed up the Delays. I currently have an additional delay in case the original 'do while readystate' loop fails to load completely, but sometimes, more or less than 6 additional seconds is required to allow the page to fully load so I can start scraping values.
Is there a way that I can 'trap' for run-time error 91, wait for an additional second, and then go back to see if 'run-time error 91' is still occurring, and if so, wait for an additional second, and go check again? In other words, I want to get rid of the additional 6 second delay and approach it one second at a time until the page is recognized as fully loaded and the run-time error 91 is gone.
The site that I am trying to scrape from is https://www.poloniex.com/exchange#btc_dgb
The code that I am using is the following:
Code:
'
Dim IE As New InternetExplorer
Dim element As Object
'
' Allow the Browser window, that we will be scraping values from, to be visible
IE.Visible = True
'
' Update status bar to inform the user of what is occurring
Application.StatusBar = "Loading website … https://www.poloniex.com/exchange#btc_dgb"
'
' Browser address that we will be scraping values from
IE.navigate "https://www.poloniex.com/exchange#btc_dgb"
'
' Allow mouse clicks and such while info is being scraped from internet ...
Do While (IE.Busy Or IE.readyState <> READYSTATE_COMPLETE) ' Create a delay to allow the webpage to fully load before proceeding
Application.Wait (Now + TimeValue("00:00:01")) ' Delay for 1 additional second and slow down the clock cycles consumed by the original loop
DoEvents ' Original delay/loop to allegedly allow the page to fully load
Loop
'
Dim Doc As HTMLDocument
Set Doc = IE.document
'
' *** ADDITIONAL DELAY that is sometimes required *** because of occasional 'Run-time error '91': Object variable or With block variable not set'
' Wait some more because sometimes all of the webpage data is not fully loaded by now
Application.Wait (Now + TimeValue("00:00:06"))
'
' Update status bar to inform the user of what is occurring
Application.StatusBar = "Gathering Data from website … https://www.poloniex.com/exchange#btc_dgb"
'
' Return SellPrice
Range("poloniex_SellPrice_1").Value = Doc.getElementsByTagName("td")(3).innerText
'
' Return BuyPrice
Range("poloniex_BuyPrice_1").Value = Doc.getElementsByTagName("td")(2).innerText
What I am wanting to do is create some type of runtime error trapping to speed up the Delays. I currently have an additional delay in case the original 'do while readystate' loop fails to load completely, but sometimes, more or less than 6 additional seconds is required to allow the page to fully load so I can start scraping values.
Is there a way that I can 'trap' for run-time error 91, wait for an additional second, and then go back to see if 'run-time error 91' is still occurring, and if so, wait for an additional second, and go check again? In other words, I want to get rid of the additional 6 second delay and approach it one second at a time until the page is recognized as fully loaded and the run-time error 91 is gone.