解析富达股票报价页面

Parsing Fidelity Stock Quote page

通过建立与 Fidelity 相关页面的连接,我已经能够从 Fidelity 获取股票和指数数据;将结果写入作品sheet;然后在 sheet.

上找到我想要的结果

我现在正在努力简化和避免同时使用 IE 和临时工作sheet 页面。下面的代码,使用Microsoft XML,v6.0 似乎下载了所有相关信息,但我不知道如何处理之后才能提取 名称最后价格Date/Time 最后一个价格。

我看过雅虎财经和 Google 财经,但他们没有我感兴趣的所有指数。

下面的代码让我开始下载页面信息,但我看到 "Get" 返回的唯一组件是 responseText(我已将其拆分并放在作品sheet供考),responseBody好像是responseText.

内容的字符编码数组

也许我一开始就不应该使用 MS XML 工具,但在我看来这应该是可能的。

感谢您的指点。


Sub FIDOQuoteTester()

'Set Reference to Microsoft XML V6.0

Const sURLPart1 As String = "http://quotes.fidelity.com/webxpress/get_quote?QUOTE_TYPE=D&SID_VALUE_ID="
Const sURLPart3 As String = "&submit=Quote"
Dim sURL As String
Dim sSymbols  As String '+ separated list
Dim REQ As MSXML2.ServerXMLHTTP60 'using Server type as the other raises security problems

Dim V As Variant, R As Range

Dim S As String

sSymbols = ".DJI+.SPX"
sURL = sURLPart1 & sSymbols & sURLPart3

Set REQ = New ServerXMLHTTP60
REQ.Open "Get", sURL, False
REQ.send

S = REQ.responseText

Stop

'putting string on worksheet for examination
'Need to split the string as it is too long for a cell.
V = Split(S, vbLf)
Set R = Range("a1").Resize(UBound(V) + 1, 1)
With R
    .EntireColumn.Clear
    .Value = WorksheetFunction.Transpose(V)
End With


End Sub

设置对 Microsoft HTML 对象库的引用。

比:

'/ Adding response text to  MSHTML

Dim oHTML       As New HTMLDocument
Dim e           '/ This is your element

oHTML.body.innerHTML = ""

oHTML.body.innerHTML = S '/ Set your responseText(HTML) here

'/ Loop through all the elements
For Each e In oHTML.all
    Debug.Print e.ID & "-->" & e.innerText
Next