gpt4 book ai didi

excel - 单击 USPS 网站上的按钮以查找 9 位邮政编码

转载 作者:行者123 更新时间:2023-12-04 10:20:19 31 4
gpt4 key购买 nike

USPS ZipCode 网站和 Excel VBA——我拥有所有用于填充网站的代码,但我无法单击带有 Excel-VBA 代码的“查找”提交按钮。

这是该站点的 URL 以及我提交的所有按钮单击代码

https://tools.usps.com/zip-code-lookup.htm?byaddress


'All of the different submit Code I have tried:

html.all.getElementById("zip-by-address").Click
html.all.getelementbytagname("zip-by-address").Click
html.document.querySelector("Find[type=submit]").Click

html.document.getElementsByClassName("btn btn-primary").Click
html.document.getElementById("zip-by-address").Click

For Each Element In ie.document.getElementsByName("zip-by-address")
If Element.className = "btn-primary" Then
Element.Click
End If
Next

ie.document.querySelector("button[type=submit]").Click

For Each Element In ie.document.getElementsByTagName("zip-by-address")
If InStr(Element.innerText, "Find") > 0 Then Element.Click
Next

ie.document.getElementByTagName("Find").FireEvent "onclick"

ie.document.getElementById("zip-by-address").FireEvent "onkeypress"
ie.document.getElementById("zip-by-address").FireEvent "onclick"

Set frm = ie.document.forms(0)
frm.submit

最佳答案

我还必须完成城市和州领域。您不需要选择按地址选项,因为它已经是 url 的一部分。
.querySelector("#zip-by-address").Click相当于.getElementById("zip-by-address").Click但速度更快,因为现代浏览器(咳嗽 IE 咳嗽)针对 css selectors 的选择进行了优化.

Public Sub ClickFindButton()

Dim ie As SHDocVw.InternetExplorer

Set ie = New SHDocVw.InternetExplorer

With ie

.Visible = True
.Navigate2 "https://tools.usps.com/zip-code-lookup.htm?byaddress" 'url is already by address so no need to click for it

Do
DoEvents
Loop While .Busy Or .ReadyState <> READYSTATE_COMPLETE

With .Document

.querySelector("#tCompany").Value = "The New York Times Company"

.querySelector("#tAddress").Value = "620 Eighth Avenue"

.querySelector("#tCity").Value = "New York"

.querySelector("[value=NY]").Selected = True

.querySelector("#zip-by-address").Click

Stop

End With
.Quit
End With
End Sub

关于excel - 单击 USPS 网站上的按钮以查找 9 位邮政编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60894731/

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