嗨我需要此代碼的幫助我試圖從此頁面提取數據https://finance.yahoo.com/quote/ADM.L/balance-sheet?p=ADM.L, 但問題是頁面默認設置爲年度,但我需要每季度的總資產值和總負債。使用Excel VBA提取雅虎財務數據
此代碼可以運行,但大部分時間都是選擇年度值。請提出一些我可以做的事情。
Private Sub CommandButton3_Click()
'
Dim ie As Object
Set Rng = Range("A2:A50")
Set Row = Range(Rng.Offset(1, 0), Rng.Offset(1, 0).End(xlDown))
Set ie = CreateObject("InternetExplorer.Application")
With ie
'.Visible = False
For Each Row In Rng
.navigate "https://finance.yahoo.com/quote/" & Range("A" & Row.Row).Value & "/balance-sheet?p=" & Range("A" & Row.Row).Value
'Application.Wait (Now + TimeValue("0:00:02"))
While ie.readyState <> 4
Wend
Do While ie.Busy: DoEvents: Loop
Dim doc As HTMLDocument
Set doc = ie.document
doc.getElementsByClassName("P(0px) M(0px) C($actionBlue) Bd(0px) O(n)")(2).Click
Do While ie.Busy: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:05"))
Range("D" & Row.Row).Value = doc.getElementsByClassName("Fw(b) Fz(s) Ta(end)")(4).innerText
Range("E" & Row.Row).Value = doc.getElementsByClassName("Fw(b) Fz(s) Ta(end)")(12).innerText
Range("F" & Row.Row).Value = doc.getElementsByClassName("C($gray) Ta(end)")(0).innerText
Next Row
End With
ie.Quit
'
End Sub
*請建議一些我可以做的事情。* - 在將元素寫入工作表之前,您可以使用IE選擇季度數據。 –
我做到了,但總是無法正常工作......大多數情況下,它正在收集季度數據 –
我認爲您希望它能夠提取季度數據? – Rdster