gpt4 book ai didi

javascript - 通过vba点击Href链接

转载 作者:行者123 更新时间:2023-11-30 20:43:02 26 4
gpt4 key购买 nike

我正在尝试通过 vba-excel 为以下链接创建 IEautomation。

网址:http://qpldocs.dla.mil/search/default.aspx

代码包括搜索字符串“QPL-631”,然后单击相应的 java 脚本链接 MIL-I-631D(6)。当我检查“MIL-I-631D(6)”链接时,我发现以下是 href 标签的源代码

<a href="javascript:__doPostBack('search_list$DG$ctl03$ctl00','')">MIL-I-631D(6)</a>

因此 href 没有点击选项链接和手动点击地址href链接与 href 地址完全不同。所以我被困在这里。我想添加一个点击“MIL-I-631D(6)”并输出结果的代码。

我已经尝试了以下代码,但到目前为止无法继续。

Private Sub IE_Autiomation()

Dim i As Long

Dim IE As Object

Dim objElement As Object

Dim objCollection As Object

Dim ae As HTMLLinkElement

Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True
IE.navigate "http://qpldocs.dla.mil/search/default.aspx"
Application.StatusBar = "Loading. Please wait..."

Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop

Application.StatusBar = "Search form submission. Please wait..." IE.document.getElementById("Search_panel1_tbox").Value = "QPL-631" IE.document.getElementById("Search_panel1_btn").Click Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop

631 Link

最佳答案

这是一个写入工作表的临时解决方案,因为您已经对产品代码“QPL-631”进行了硬编码,您可以直接跳到在 URL 字符串中使用它来返回结果。

注意:我已从该页面提取表 ID:

html.getElementById("Lu_gov_DG")

您可能想探索这是否是跨产品的共同主题(我想是的)。会让生活轻松很多。您甚至可以完全放弃 IE,转而采用更快的 XHR 解决方案。

Option Explicit

Private Sub IE_Automation()

'References Internet Controls and HTML Object library

Dim i As Long
Dim IE As Object
Dim html As HTMLDocument

Dim product As String
product = "QPL-631"

Dim url As String

url = "http://qpldocs.dla.mil/search/parts.aspx?qpl=1528&param=" & product & "&type=256"

Set IE = CreateObject("InternetExplorer.Application")

With IE

.Visible = True

.navigate url '"http://qpldocs.dla.mil/search/default.aspx"

Application.StatusBar = "Loading. Please wait..."

Do While .Busy = True Or .readyState <> 4: DoEvents: Loop

Set html = .Document

Dim allRowOfData As Object

Set allRowOfData = html.getElementById("Lu_gov_DG")

Dim r As Long, c As Long

Dim curHTMLRow As Object

For r = 1 To allRowOfData.Rows.Length - 1

Set curHTMLRow = allRowOfData.Rows(r)

For c = 0 To curHTMLRow.Cells.Length - 1
Cells(r + 1, c + 1) = curHTMLRow.Cells(c).innerText
Next c

Next r

.Quit

End With

Application.StatusBar = False 'And tidy up our change to the status bar

End Sub

有回传的例子here ,我会看看。

引用:

  1. > How to reset the Application.StatusBar

关于javascript - 通过vba点击Href链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49045141/

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