Someone answered my question for Java and I'm basically building on a previous answer provided by @enderland here.
I'm running a webscraper and generally it works well but I often run into "runtime errors". I want to avoid this by skipping a specific assignment (in my case loading a patent page on Google.) if the time it takes to load the website takes too long.
I reckon a simple If Then
is what I need but I don't know which function to use to control the elapsing of time.
Any suggestions?
At the moment I run the following:
Function citecount(patent_number As String, patent As String, ccount As Integer, info As String)
patent = ""
ccount = 0
If patent_number = "" Then Exit Function
the_start:
Set ie = CreateObject("InternetExplorer.Application")
ie.Top = 0
ie.Left = 0
ie.Width = 800
ie.Height = 600
ie.Visible = False 'If False we won't see the window navigation
On Error Resume Next
ie.Navigate ("http://www.google.com/patents/US" & patent_number & "?")
Sleep (600)
Do
DoEvents
If Err.Number <> 0 Then
ie.Quit
Set ie = Nothing
GoTo the_start:
End If
Sleep (1250)
Loop Until ie.ReadyState = 4
With Sleep()
being defined as:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
The main error I face is described here. It's a Run-time error '2147467259 (80004005) automation error, unspecified error
. Additionally, before I added the Sleep()
commands I also got Microsoft Excel is waiting for another Application to complete an on OLE action
but that has not come back since adding the Sleep()
command.
Finally I get an IE warning:
Stop running this script?
A Script on thispage is causing your web browser to run slowly. If it continues to run your computer might become unresponsive
These are I think all caused by the fact that the webpage is taking loads of time downloading images that I do not need. I read some posts about loading a webpage directly in html without images on SO but could not find one that I could implement (novice at work).
Hope this provides clarification