excel - 为什么我的 VBA 代码无法选择 "Download"来下载此特定网站的 .xls 文件?

标签 excel vba

早上好,

我想知道为什么我的代码特别不能在这个网站上运行。我希望能够让它按“下载”以启动下载 .xls 文件的过程。但是,它没有,我无法弄清楚。

Public IE As InternetExplorer

Public Sub Main()
  Call InitiateIE
  IE.navigate ("https://www.auction.com/event/details/E-11142/?filter=reset")
  Call LoadIE
  IE.Document.getElementsByClassName("button-root_button_jzfF button-role-default_button_3iu5 button-is-medium_button_3vqd navigation-btn_styles_M1TS download-inventory-btn_styles_3ytA navigation-container-element_styles_3MZ0")(0).Click
  Call LoadIE
  IE.Quit
End Sub

Private Sub InitiateIE()
  Set IE = New InternetExplorer
  IE.Visible = True
End Sub

Private Sub LoadIE(Optional BufferTime As Long = 1000)
  Do While IE.Busy
  Loop
  Do Until IE.Document.ReadyState = "complete" Or IE.Document.ReadyState = "interactive"
  Loop
End Sub

最佳答案

顺便说一句,我会使用属性 = 值 CSS 选择器 btw

ie.document.querySelector("[data-elm-id='event_details_download_auction_inventory']").Click

带 Chrome 的 Selenium Basic:
Option Explicit
Public Sub GetDownload()
'VBE > Tools > References > Selenium Type Library
'Requires latest chrome browser and chrome driver
'Chrome driver containing folder must be on environmental path
'Download selenium https://github.com/florentbr/SeleniumBasic/releases/tag/v2.0.9.0
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://www.auction.com/event/details/E-11142/?filter=reset"

    With d
        .Start "Chrome"
        .get URL
        .FindElementByCss("[data-elm-id='event_details_download_auction_inventory']").Click
        .Quit
    End With
End Sub

Other selenium info

Environmental path - 驱动程序必须位于此路径上的文件夹中。

关于excel - 为什么我的 VBA 代码无法选择 "Download"来下载此特定网站的 .xls 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53190879/

相关文章:

c# - 如何使用C#获取Excel中当前打开的文档?

Python:Pandas read_excel 无法打开 .xls 文件,不支持 xlrd

vba - 发送带有附件的电子邮件 VBA

excel - 复制后在原稿上选择目标粘贴范围

excel - 在 excel 或 vba 中查找值

java - 从 Excel 文件 (xlsx) 创建模板文件 (xltx)

java - 如何使用 Java 中的 Apache POI 从 Excel 读取/写入 XML map ?

excel - 查找公式以减去最后一个输入数据点

excel - 以编程方式格式化添加控件以适合单元格

excel - 两次关闭工作簿时的奇怪行为