rainbowsperm wrote:
像https://www.macromicro.me/charts/20069/tw-mtx-long-to-short-ratio-of-individual-player
這種沒有form data的網站 有可能抓到他圖表上每日的值嗎?
寫法類似1064樓,要先拿到key才能取得資料
最近可參考的範例是1106樓
json取出、畫圖,這部份的程式碼,以您的能力,應該不是問題,請自行練習看看
*因網頁改版,此範例失效,請參考1329樓*
圖片來源:財經M平方 www.macromicro.me

Sub Get_Macromicro_Charts_JSON_Data()
Dim URL As String, URL_a As String, GetXml As Object, Jsondata As Object, DecodeJson, BlueLine, RedLine, datastk As String
Set GetXml = CreateObject("Msxml2.XMLHTTP")
Set Jsondata = CreateObject("HtmlFile")

URL = "https://www.macromicro.me/charts/data/20069"
URL_a = "https://www.macromicro.me/charts/20069/tw-mtx-long-to-short-ratio-of-individual-player"
With GetXml
.Open "GET", URL_a, False
.send
datastk = Split(Split(.responsetext, "data-stk=""")(1), """>")(0)
.Open "GET", URL, False
.setRequestHeader "Accept", "application/json, text/javascript, */*; q=0.01"
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
.setRequestHeader "Authorization", "Bearer " & datastk
.setRequestHeader "Referer", URL_a
.send
Set DecodeJson = CallByName(CallByName(Jsondata.JsonParse(.responsetext), "data", VbGet), "c:20069", VbGet)
'台灣-小台指散戶多空比
Set BlueLine = CallByName(CallByName(DecodeJson, "s", VbGet), 0, VbGet)
'台灣 -加權股價指數
Set RedLine = CallByName(CallByName(DecodeJson, "s", VbGet), 1, VbGet)
'==================
'blueline、redline,json整理用程式碼放這裡


'==================
End With
Set GetXml = Nothing
Set Jsondata = Nothing
Set DecodeJson = Nothing
Set BlueLine = Nothing
Set RedLine = Nothing
End Sub