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

时间:2017-04-23 10:20:36

标签: vba webpage access

大家好,在我的Access& 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)

1 个答案:

答案 0 :(得分:1)

然后在点击按钮上添加等待答案页面 您可以通过名称

访问文本字段值
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