在过去的几天里,我一直在运行这个代码来导航到这个城市数据网页,它一直运行得很好,但突然之间,我得到了围绕readyState = 4的无限循环,奇怪的是,它有时起作用,有时不起作用。
下面是我的代码:
Dim IE as Object
Dim pageaddress as string
Dim city as string
Dim state as string
city = "Chicago"
state = "Illinois"
Set IE = CreateObject("internetExplorer.Application")
IE.Visible = True
pageaddress = "http://www.city-data.com/housing/houses-" & city & "-" & state & ".html"
IE.navigate (pageaddress)
Do
DoEvents
Loop Until IE.readyState = 4发布于 2018-03-25 09:54:04
不幸的是,这是网页本身的问题,而不是你的代码。这意味着您必须添加一个计时器,并在分配的时间之后刷新页面。
我会记下该页面的平均加载时间,并选择一个远高于该平均值的合理时间。
在本例中,我们将使用10秒。
Dim IE As Object
Dim pageaddress As String
Dim city As String
Dim state As String
Dim maxLoadingTime As Single, myTimer As Single
city = "Chicago"
state = "Illinois"
Set IE = CreateObject("internetExplorer.Application")
IE.Visible = True
pageaddress = "http://www.city-data.com/housing/houses-" & city & "-" & state & ".html"
IE.navigate (pageaddress)
'Set the max time to load
maxLoadingTime = 10 '< -- # of seconds to allow page to load -- <
myTimer = Timer
Do
DoEvents
If Timer >= maxLoadingTime + myTimer Then
Debug.Print Time & " Notice: Connection Error. Refreshing webpage"
IE.stop
IE.Refresh
End If
Loop Until IE.readyState = 4发布于 2020-02-13 20:48:57
我使用: For t=1 To 1000: If objIE.readyState <> 4 Or objIE.Busy Then t= 1: DoEvents: Next t确保readyState或busy不会改变。
https://stackoverflow.com/questions/49471301
复制相似问题