首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReadyState =3上的ReadyState Complete卡住

ReadyState =3上的ReadyState Complete卡住
EN

Stack Overflow用户
提问于 2018-03-25 08:13:02
回答 2查看 1.1K关注 0票数 0

在过去的几天里,我一直在运行这个代码来导航到这个城市数据网页,它一直运行得很好,但突然之间,我得到了围绕readyState = 4的无限循环,奇怪的是,它有时起作用,有时不起作用。

下面是我的代码:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2018-03-25 09:54:04

不幸的是,这是网页本身的问题,而不是你的代码。这意味着您必须添加一个计时器,并在分配的时间之后刷新页面。

我会记下该页面的平均加载时间,并选择一个远高于该平均值的合理时间。

在本例中,我们将使用10秒。

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 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不会改变。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49471301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档