nijawang wrote:
那是不是變成只能用抓關鍵字來取得報價?
不過好像也不能用原本的GetXml方式了。
只需要少許資料,用關鍵字是最快、最簡單的
Sub Get_Yahoo_vti_text()
Dim UrL As String, GetXml As Object, Price As String, ttt As Double
Set GetXml = CreateObject("msxml2.xmlhttp")
ttt = Timer
UrL = "https://tw.stock.yahoo.com/quote/vti"
With GetXml
.Open "GET", UrL, False
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Pragma", "no-cache"
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send
Price = Split(Split(.responsetext, """previousVolume"":null,""price"":""")(1), """,""regularMarketDayHigh""")(0)
End With
'debug
MsgBox "成交 " & Price & vbNewLine & Timer - ttt & "s", vbOKOnly, "report"
Set GetXml = Nothing
End Sub
nijawang wrote:
今天Yahoo!的美股報價好像把table拿掉,換成flex屬性。
https://tw.stock.yahoo.com/quote/vti
'只要表格資料

Sub Get_Yahoo_vti_Json_1()
Dim UrL As String, GetXml As Object, Jsondata As Object, DecodeJson, ttt As Double
Set GetXml = CreateObject("msxml2.xmlhttp")
Set Jsondata = CreateObject("HtmlFile")

ttt = Timer
UrL = "https://tw.stock.yahoo.com/quote/vti"
With GetXml
.Open "GET", UrL, False
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Pragma", "no-cache"
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send
Set DecodeJson = CallByName(Jsondata.JsonParse("{""data"":" & Split(Split(.responsetext, """quote"":{""data"":")(1), ",""isFailed"":")(0) & "}"), "data", VbGet)
End With
'========================
'json整理用程式碼放這裡
'debug
MsgBox "成交 " & CallByName(DecodeJson, "price", VbGet) & vbNewLine & Timer - ttt & "s", vbOKOnly, "report"
'========================
Set GetXml = Nothing
Set Jsondata = Nothing
Set DecodeJson = Nothing
End Sub
'表格、含圖表原始資料

Sub Get_Yahoo_vti_Json_2()
Dim UrL As String, GetXml As Object, Jsondata As Object, DecodeJson, ttt As Double
ttt = Timer
Set GetXml = CreateObject("msxml2.xmlhttp")
Set Jsondata = CreateObject("HtmlFile")

'當日
UrL = "https://tw.stock.yahoo.com/_td-stock/api/resource/FinanceChartService.ApacLibraCharts;autoRefresh=" & UNIXTime & ";period=1m;range=1d;symbols=[""VTI""];type=null?bkt=&device=desktop&ecma=modern&feature=ecmaModern,useVersionSwitch,useNewQuoteTabColor&intl=tw⟪=zh-Hant-TW&partner=none&prid=7c6hs39hdihpb®ion=TW&site=finance&tz=Asia/Taipei&ver=1.2.1415&returnMeta=true"
'5天
'UrL = "https://tw.stock.yahoo.com/_td-stock/api/resource/FinanceChartService.ApacLibraCharts;autoRefresh=" & unixtime & ";period=15m;range=5d;symbols=[""VTI""];type=null?bkt=&device=desktop&ecma=modern&feature=ecmaModern,useVersionSwitch,useNewQuoteTabColor&intl=tw⟪=zh-Hant-TW&partner=none&prid=7c6hs39hdihpb®ion=TW&site=finance&tz=Asia/Taipei&ver=1.2.1415&returnMeta=true"
With GetXml
.Open "GET", UrL, False
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Pragma", "no-cache"
.setRequestHeader "Referer", "https://tw.stock.yahoo.com/quote/vti"
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send
Set DecodeJson = CallByName(CallByName(CallByName(Jsondata.JsonParse(.responsetext), "data", VbGet), "0", VbGet), "chart", VbGet)
End With
'========================
'json整理用程式碼放這裡
'debug
MsgBox CallByName(CallByName(DecodeJson, "meta", VbGet), "symbol", VbGet)
'========================
Set GetXml = Nothing
Set Jsondata = Nothing
Set DecodeJson = Nothing
End Sub
Function UNIXTime()
UNIXTime = Round(((Date - #1/1/1970#) * 86400 + Timer) * 1000, 0)
End Function
較新的json整理範例請參考,1024樓、1161樓、1168樓…或參考其它舊範例