由于出现错误80020101,使用的网页无法完成操作



我想从这个url中提取一个表,但我遇到了两个问题:

  1. 在我获得表格之前,我需要更新通过单击Vol.Column旁边的齿轮而更改的列,需要根据图片进行设置,然后单击"Aceptar"。屏幕截图1

当我试图运行我的脚本时;点击";齿轮我有以下错误屏幕截图2

  1. 假设前面的问题已经解决,我该如何获取表格?我应该重新加载页面吗
    这里是代码:
Sub table ()
Dim ie As InternetExplorer
Dim CurrentWindow As HTMLWindowProxy
Url = "https://es.investing.com/stock-screener/?sp=country::5|sector::a|industry::a|equityType::a|exchange::a|eq_market_cap::110630000,1990000000000%3Ceq_market_cap;1"
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate Url
Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop
Set html = ie.document
Set CurrentWindow = html.parentWindow
Call CurrentWindow.execScript("columnsSettings_stock_screener.colSelectIconClick(event)") 'This line brings the error
End Sub

使用execScript执行onclick函数,然后循环并取消选择不需要的项目,以便选择所需的项目。

请单独问一个关于刮桌子的问题。首先让这一点发挥作用,但请注意,它有一个很好的清晰id,你可以使用resultsTable,所以我只需用ie.document.querySelector("#resultsTable")抓取,然后使用剪贴板将.outerHTML传输到Excel,这样表就可以复制粘贴到Excel中。

Option Explicit
Public Sub table()
Dim ie As SHDocVw.InternetExplorer, i As Long, url As String

url = "https://es.investing.com/stock-screener/?sp=country::5|sector::a|industry::a|equityType::a|exchange::a|eq_market_cap::110630000,1990000000000%3Ceq_market_cap;1"

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate url

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

ieDocument.execScript "columnsSettings_stock_screener.colSelectIconClick(new Event('click'));)" 'or uglier columnsSettings_stock_screener.colSelectIconClick(document.querySelector('#colSelectIcon_stock_screener').click());

Dim switchOffs(), switchOns(), selector As String

switchOffs = Array(6, 7, 10, 11)
switchOns = Array(1, 2, 3, 4, 5, 8, 9)

With ie.document

For i = LBound(switchOffs) To UBound(switchOffs)

selector = "#SS_" & CStr(switchOffs(i))

With .querySelector(selector)
If .Checked = True Then .Click 'vba you may be able to do If .Checked Then .Click
End With

Next
For i = LBound(switchOns) To UBound(switchOns)

selector = "#SS_" & CStr(switchOns(i))

With .querySelector(selector)
If .Checked = False Then .Click 'vba you may be able to do If not .Checked Then .Click
End With

Next

End With
Stop
End Sub

我不熟悉vba脚本,但在行:

Call CurrentWindow.execScript(
"columnsSettings_stock_screener.colSelectIconClick(event)"
)

未定义event。如果您在浏览器中打开页面并运行:

columnsSettings_stock_screener.colSelectIconClick(event)

在你的开发工具中,你会得到:

Uncaught TypeError: Cannot read property 'stopPropagation' of undefined
at ColumnsSettings.colSelectIconClick (columnsSettings-1.22.min.js:2)
at <anonymous>:1:32

既然你想模拟点击,你可以这样做:

Call CurrentWindow.execScript(
"columnsSettings_stock_screener.colSelectIconClick(new Event('click'))"
)

最新更新