如何将span id值转换为excel VBA?

时间:2022-04-25 01:27:10

Ok so here is my entire code:

这是我的全部代码

Private Sub CommandButton1_Click()

Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")

With appIE
    .Navigate "http://finance.yahoo.com/q/ks?s=" & "AAPL"
    .Visible = True
End With

Do While appIE.Busy
    DoEvents
Loop

Set getPrice = appIE.Document.getElementById("yfs_l84_aapl")
Dim myValue As String: myValue = getPrice.Cells(1).innerHTML

appIE.Quit
Set appIE = Nothing

Range("B1").Value = myValue

End Sub

And here is the HTML that I'm trying to read into Excel (specifically, I need the 113.92):

这是我要读到Excel的HTML(具体来说,我需要113.92):

<span id="yfs_l84_aapl">113.92</span>

What do I have to change in these two lines of code to read a "span id"?

我需要在这两行代码中修改什么才能读取“span id”?

Set getPrice = appIE.Document.getElementById("yfs_l84_aapl")
Dim myValue As String: myValue = getPrice.Cells(1).innerHTML

Or, alternatively, is there a way just to read whatever is directly after "yfs_184"??

或者,有没有一种方法可以直接读取“yfs_184”之后的内容?

I'm brand new to coding and am working very hard to get better, so any help is really appreciated!! Thanks! :)

我是一个全新的编码和努力工作,以得到更好的,所以任何帮助都是非常感谢!谢谢!:)

1 个解决方案

#1


1  

Use this:

用这个:

myValue = getPrice.innerText

#1


1  

Use this:

用这个:

myValue = getPrice.innerText