【发布时间】:2021-02-03 11:15:56
【问题描述】:
我想通过选择特定日期从网站下载文件。检查显示 href 内容的元素,但无法点击它。
网页代码
<td>
<a href="/content/historical/EQUITIES/2021/FEB/cm02FEB2021bhav.csv.zip" target="new">cm02FEB2021bhav.csv.zip</a><br>
</td>
我的 VBA 代码
Dim files As String
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://www1.nseindia.com/products/content/equities/equities/archieve_eq.htm"
IE.Visible = True
While IE.readystate <> 4: DoEvents: Wend
Do
Set el = Nothing
On Error Resume Next
Set el = IE.document.getelementbyid("h_filetype")
On Error GoTo 0
DoEvents
Loop While el Is Nothing
IE.document.getelementbyid("h_filetype").Value = "eqbhav"
Do
Set el = Nothing
On Error Resume Next
Set el = IE.document.getelementbyid("date")
On Error GoTo 0
DoEvents
Loop While el Is Nothing
IE.document.getelementbyid("date").Value = "02-02-2021
IE.document.parentWindow.execScript "validateInput();", "javascript"
IE.document.querySelector("a[href^='/content/historical/EQUITIES/']").Click
我已经尝试了下面的代码,但它不起作用。
IE.document.querySelector("a[href^='/content/historical/EQUITIES/']").Click
【问题讨论】:
-
另外,除了说“不工作”,你能补充更多细节吗?是否有任何错误信息?如果有,是什么,在哪里?