登录后获取IE,更改网址

时间:2019-07-15 07:02:25

标签: excel vba

我使用Excel VBA登录Web,登录后URL更改了,登录后我无法控制该页面。

登录后:

DimSet另一个InternetExplorer对象,尝试获取页面并使用.locationURL,但它仍显示以前的URL。

我找到了一些类似于shell的方法来获取IE,但无法正常工作。 但是当我使用F8逐行运行代码时,.locationURL可以在登录后显示URL。

我该怎么做才能让第二张照片在登录后显示URL?

Dim Login As InternetExplorer
Set Login = CreateObject("InternetExplorer.Application")
Login.Visible = True
Login.navigate ("This is Login page")
Do While Login.Busy Or Login.readyState <> 4: DoEvents: Loop
Debug.Print Login.LocationURL ' show URL of login page

Login.document.getElementsByTagName("input")("tbx_No").Value = ID
Login.document.getElementsByTagName("input")("tbx_Pwd").Value = pwd
Login.document.getElementsByTagName("input")("btn_ok").Click
Do While Login.Busy Or Login.document.readyState <> "complete": Loop

Debug.Print Login.LocationURL ' show URL of page after login

编辑:

Dim Login As InternetExplorer
Set Login = CreateObject("InternetExplorer.Application")
Login.Visible = True
Login.navigate ("This is Login page")
Do While Login.Busy Or Login.readyState <> 4: DoEvents:
Debug.Print Login.Busy & " " & Login.readyState
Loop
Debug.Print Login.LocationURL

Login.document.getElementsByTagName("input")("tbx_No").Value = ID
Login.document.getElementsByTagName("input")("tbx_Pwd").Value = pwd
Login.document.getElementsByTagName("input")("btn_ok").Click
Do While Login.Busy Or Login.document.readyState <> "complete": DoEvents:
Debug.Print Login.Busy & " " & Login.document.readyState
Loop
Sleep (5000)
Do Until Login.LocationURL = "This is page after login": DoEvents: Loop
Debug.Print Login.LocationURL

像这样调试打印:

True 1
True 1
True 1
False 4
This is Login page

并且代码仍在运行,我认为它停留在:

Do Until Login.LocationURL = "This is page after login": DoEvents: Loop

但是为什么不显示第二个:

Debug.Print Login.Busy & " " & Login.document.readyState

0 个答案:

没有答案