我尝试了几天,使用VBA指令从Yahoo财务获取公司的资产负债表数据,例如“ .getElementsByTagName”,但该方法不起作用...什么也没发生,我被卡住了...
有什么想法吗?参见下面的代码:
Sub Get_Data()
Dim url As String
Dim http As Object
Dim TR_col As Object,Tr As Object
Dim TD_col As Object,Td As Object
Dim row As Long,col As Long
Dim html As Object
Dim tbl As Object
'
On Error Resume Next
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0") 'CreateObject("MSXML2.ServerXMLHTTP.6.0")
url = "https//finance.yahoo.com/quote/AAPL/balance-sheet?p=AAPL"
http.Open "POST",url,False
http.setRequestHeader "Content-Type","text/xml"
http.Send
MsgBox http.responseText
Set html = CreateObject("htmlfile")
html.body.innerHTML = http.responseText
Set tbl = html.getElementById("Pos(r)")
row = 1
col = 1
Set TR_col = html.getElementsByTagName("TR")
For Each Tr In TR_col
Set TD_col = Tr.getElementsByTagName("TD")
For Each Td In TD_col
Cells(row,col) = Td.innerText
col = col + 1
Next
col = 1
row = row + 1
Next
End Sub