我试图从数千个不同(但相似)的网页中抓取特定数据点。 (我需要不同公司的EBITDA)。请参阅下面的代码。
请参阅下面的宏代码。
Enum READYSTATE
READYSTATE_UNINITIALIZED = 0
READYSTATE_LOADING = 1
READYSTATE_LOADED = 2
READYSTATE_INTERACTIVE = 3
READYSTATE_COMPLETE = 4
End Enum
Sub TAM_Click()
Dim ticker As String
Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim RowNumber As Integer
Set ie = New InternetExplorer
ie.Visible = False
RowNumber = 6
ticker = Sheet1.Cells(RowNumber, 3)
ie.navigate "financials.morningstar.com/income-statement/is.html?t=" +
ticker + "&ops=clear"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Set html = ie.document
Dim ElementList As IHTMLElement
Dim Elements As IHTMLElementCollection
Dim Element As IHTMLElement
Set ElementList = html.getElementById("data_i90")
Set Elements = ElementList.Children
For Each Element In Elements
If Element.ID = "Y_6" Then
Debug.Print Element.innerText
End If
Next Element
我收到运行时错误91对象变量或未设置块变量
通过反复试验,我确定问题在于设置变量元素和元素。
谁能告诉我自己可能做错了什么?非常感谢任何帮助/代码评论。
我认为错误可能是使用ElementList.Children操作无法调用嵌套在IHTMLElementCollection中的HTML标记..至少那是我获得运行时错误91的第一行。我需要检查网页的HTML,看看为什么我不能这样做