我正在尝试自动执行从网站下载CSV的过程。
我设法将代码写入:
从那里,我的问题就开始了。单击该链接后,该站点将执行一系列Ajax调用,并显示一个div,其中包含一个链接,用于下载每次具有唯一名称的文件。我可以弹出框,但是我无法让VBA在链接可用后单击该链接。任何人都可以帮助让VBA点击ajax调用后显示的框中的链接吗?
Sub GetTableData()
Dim ieApp As InternetExplorer
Dim ieDoc As Object
Set ieApp = New InternetExplorer
ieApp.Visible = True
ieApp.Navigate "https://www.thesite.com/Login.aspx"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
On Error GoTo downloadPage
testPage = ieDoc.getElementById("file_box_link_id")
With ieDoc
.getElementById("EMail").Value = "me@web.com"
.getElementById("Password").Value = "pass"
.getElementById("Submit").Click
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
ieApp.Navigate "https://www.thesite.com/Menu.aspx"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
downloadPage:
ieDoc.getElementById("download_link").Click
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
' THIS IS WHERE THE PROBLEM COMES...THIS HTML IS ADDED AFTER THE AJAX CALL
dlLink = ieDoc.getElementById("download_link")
Debug.Print dlLink.href
ieApp.Quit
Set ieApp = Nothing
End Sub
答案 0 :(得分:0)
我不确定您是否可以从弹出窗口获取任何数据,但如果可以,请尝试使用getElementsByTagName方法和outerText属性。
For Each Link In ieDoc.getElementsByTagName("a") Do
If Link.outerText = "The link text" Then
Link.Click
Exit For
End If
Next
您可以找到更多信息here
希望有所帮助!
祝你好运, 路易斯费尔南多