|
楼主 |
发表于 2012-1-13 02:41
|
显示全部楼层
本帖最后由 liucqa 于 2012-1-13 10:08 编辑
计数器法
Private Sub CommandButton1_Click()
countFrame = 1 '假设3个框架,那么DocumentComplete就要执行4次,因此计数初始为1(整个页面算一个)
Sheet2.WebBrowser1.Navigate2 "https://dynamic.12306.cn/otsweb/"
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
countFrame = countFrame + 1
MsgBox "BeforeNavigate2加1 countFrame=" & countFrame
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If pDisp.LocationURL = WebBrowser1.Object.LocationURL Then MsgBox "网址判断加载结束"
If pDisp Is WebBrowser1.Object Then MsgBox "finished loading bject"
countFrame = countFrame - 1
MsgBox "DocumentComplete减1 countFrame=" & countFrame
If countFrame = 0 Then MsgBox "计数器判断加载结束"
End Sub
用计数器试了一下,发现还是比较准的,计算出了由于安全问题导致的第二次加载页面。测试发现不能用DownloadBegin 事件,只能用BeforeNavigate2事件计数
注意第一次启动因计数器未初始化,会导致计算错误。不用管它。点击按钮才是正确的。注意提示证书问题时,请选择“是”
上述程序对12306有效,对别的网址,可能需要调整计数器的初始值
|
|