VBA打开网页,登录并获得打开的页面

问题描述:


大家好,在我访问& VBA小应用程序的功能打开一个网页,填写用户名和密码,然后登录。VBA打开网页,登录并获得打开的页面

如何从刚刚登录的打开的网页中读取文本字段和其他内容,而不是在具有相同链接的新网页中打开?

这是我的代码。

感谢所有

Private Sub myButton_Click() 
Dim IE As Object 
Dim IEDoc As HTMLDocument 

Set IE = CreateObject("InternetExplorer.application") 
Set IEDoc = IE.Document 
IE.Navigate "http://mylogin.com" 
Do While IE.Busy: DoEvents: Loop 
While IE.ReadyState <> READYSTATE_COMPLETE 
DoEvents 
Wend 

With IEDoc 
     .getElementsByName("userid")(0).Value = "user" 
     .getElementsByName("password")(0).Value = "password" 
     .getElementById("btn_login").Click 
End With 

'At this point, I would read a text field from the new opened page, after login, in the same browser (not from a new webpage with the same link) 

您添加等待答案页面上点击按钮,然后 您可以通过它的名称来访问文本框值

Private Sub myButton_Click() 
Dim IE As Object 
Dim IEDoc As HTMLDocument 

Set IE = CreateObject("InternetExplorer.application") 
Set IEDoc = IE.Document 
IE.Navigate "http://mylogin.com" 
Do While IE.Busy: DoEvents: Loop 
While IE.ReadyState <> READYSTATE_COMPLETE 
DoEvents 
Wend 

With IEDoc 
     .getElementsByName("userid")(0).Value = "user" 
     .getElementsByName("password")(0).Value = "password" 
     .getElementById("btn_login").Click 
End With 

'At this point, I would read a text field from the new opened page, after login, in the same browser (not from a new webpage with the same link) 
Do While IE.Busy: DoEvents: Loop 
While IE.ReadyState <> READYSTATE_COMPLETE 
    DoEvents 
Wend 
With IEDoc 
     msgbox .getElementsByName("thetextfield").Value 
End With