gpt4 book ai didi

html - 按登录按钮 Excel Vba

转载 作者:太空宇宙 更新时间:2023-11-04 15:47:40 25 4
gpt4 key购买 nike

我有下面的代码可以在代码中登录网站。但是,未单击登录按钮。我是 Excel VBA 的新手,请问您有什么建议?

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub Myenter()

Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://willemendrees.nl/fn/login/"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.id_username.Value = "amsterdam@willemendrees.nl"
HTMLDoc.all.id_password.Value = "*****"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next
End With
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub

最佳答案

您可以使用 CSS attribute = value [tabindex='3'] 的选择器。这通过值为 3 的 tabindex 属性定位登录按钮。

HTMLDoc.querySelector("[tabindex='3']").Click

整个事情:

Option Explicit
Public Sub AttemptLogin()
Dim IE As New InternetExplorer
With IE
.Visible = True
.Navigate2 "https://willemendrees.nl/fn/login/"

While .Busy Or .readyState < 4: DoEvents: Wend

With .document
With .querySelector("#id_username")
.Focus
.Value = "amsterdam@willemendrees.nl"
End With
With .querySelector("#id_password")
.Focus
.Value = "***"
End With
.querySelector("[tabindex='3']").Click
End With

While .Busy Or .readyState < 4: DoEvents: Wend

Stop '<== Delete me later
.Quit
End With
End Sub

关于html - 按登录按钮 Excel Vba,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53615797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com