【发布时间】:2021-01-08 20:56:36
【问题描述】:
Snapshot on the table i would like to get 我想从华尔街日报导入财务报表。我设计了一个代码(如下),但它似乎不起作用。当我运行它时,我得到“运行时错误 91 对象变量或未设置块变量”。单击调试后,带星号的行以黄色突出显示。
Can anyone assist?
Here is the code I wrote
Sub finanacialdata()
Dim ieobj As InternetExplorer
Dim htmlele As IHTMLElement
Dim i As Integer
i = 1
Set ieobj = New InternetExplorer
ieobj.Visible = True
ieobj.navigate ""https://www.wsj.com/market-data/quotes/GOL/financials/annual/balance-sheet
Application.Wait Now + TimeValue("00.00.10")
For Each htmlele In ie.obj.document.getElementsByClassName("zonedmodule")(0).getElementBytagname("tr")
With ActiveSheet
*.Range("A" & i).Value = htmlele.Children(0).textContent*
.Range("B" & i).Value = htmlele.Children(1).textContent
.Range("C" & i).Value = htmlele.Children(2).textContent
.Range("D" & i).Value = htmlele.Children(3).textContent
.Range("E" & i).Value = htmlele.Children(4).textContent
.Range("F" & i).Value = htmlele.Children(5).textContent
End With
i = i + 1
Next htmlele
End Sub
Thank you
【问题讨论】:
-
我尝试检查 VBA 代码和 WSJ 网站的源代码。从 VBA 代码中,您似乎想要访问在具有类名称“zonedmodule”的第一个元素的 TR 标记的子项中后退的文本数据。如果我们使用开发人员工具参考源代码,那么您会注意到第一个具有类名“zonedmodule”的元素是空的。由于这个原因,您不会在 Excel 工作表中获得任何数据。如果您可以显示要从该站点访问的数据的快照,那么我们可以尝试为此提供一些代码示例。
-
亲爱的迪帕克,非常感谢您的回复。我在我的原始帖子中添加了该数据的快照,我想导入。这是 GOL 航空公司的资产负债表。再次感谢您的帮助。
标签: excel vba internet-explorer