简体   繁体   English

如何将span id值获取到Excel VBA中?

[英]How to get span id value into excel VBA?

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! 谢谢! :) :)

用这个:

myValue = getPrice.innerText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM