这可能看起来很基本,但我正在尝试编写VBA代码来自动登录ESPN.com。
我的代码如下:
Sub ESPNLogIn()
Dim IE As New SHDocVw.InternetExplorer
Dim Doc As MSHTML.HTMLDocument
Dim LogIn As MSHTML.IHTMLElementCollection
Dim SignIn As MSHTML.IHTMLElementCollection
IE.Visible = True
IE.navigate "http://www.espn.com/"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set Doc = IE.document
Set LogIn = Doc.getElementsByTagName("a")
For Each logs In LogIn
If logs.innerText = "Log In" Then
logs.Click
Exit For
End If
Next logs
Set SignIn = Doc.getElementsByTagName("input")
For Each signs In SignIn
If signs.getAttribute("placeholder") = "Username or Email Address" Then
signs.Value = "James"
Exit For
End If
Next signs
End Sub
我可以访问用户名/密码页面,但是当我按照适用于其他网站的代码时,它不会为ESPN输入任何值。有人可以帮忙吗?谢谢。初学者。