VBA 网页抓取

VBA web scraping

我正在尝试从本网站的 table 获取一行数据:http://www.nasdaq.com/symbol/neog/financials?query=balance-sheet

现在我可以使用

获取 "total liabilities" 行
doc.getelementsbyclassname("net")(3).innertext 

但我不知道如何获取任何其他数据行,例如普通股。

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = Range("bscode").Row And _
Target.Column = Range("bscode").Column Then
Dim IE As New InternetExplorer
IE.Visible = True
IE.navigate "http://www.nasdaq.com/symbol/" & Range("bscode").Value & "/financials?query=balance-sheet&data=quarterly"

Do
 DoEvents

Loop Until IE.readyState = READYSTATE_COMPLETE

Dim Doc As HTMLDocument
Set Doc = IE.document
Dim sD As String
sD = Doc.getElementsByTagName("tr")(8).innerText

MsgBox sD

Dim aD As Variant
aD = Split(sD, "$")
Range("bs").Value = aD(1)
Range("ba").Value = aD(2)
Range("bb").Value = aD(3)
Range("bc").Value = aD(4)

End If
End Sub

如果有帮助,我有 HTML 来源和突出显示的 tr 我想获取。

screenshot of HTML code

问题是查找 table 行数据的方法。有人可以向我解释如何获取其他数据行吗?将不胜感激!

我能够通过这种方式进行一些试验和错误并获得正确的参考:

Dim eTR As Object, cTR As Object, I as Integer 'I used object, because I did late binding
Set cTR = Doc.getElementsByTagName("tr")

i = 0

For Each eTR In cTR

    If Left(eTR.innerText, 3) = "Com" Then

        Debug.Print "(" & i; "): " & eTR.innerText

    End If

    i = i + 1

Next

立即window然后显示

(308): Common Stocks ... (a bunch of space) ... ,941,877,773,779

然后我测试了这个语句:

sd = Doc.getElementsByTagName("tr")(308).innerText
Debug.Print sd

得到了同样的结果。