usbsilence wrote:
您在這帖小台指散戶多空比資料 已經無法執行了 請教如何修改
https://www.mobile01.com/topicdetail.php?f=511&t=4737630&p=112
卡在
datastk = Split(Split(.ResponseText, "data-stk=""")(1), """>")(0)
不知如何修改 請指導一下 謝謝您
網頁改版,需多加入cookie,可參考1293樓
(另外,因為無法下載,應該是卡在json那行才對)
圖片來源:財經M平方 www.macromicro.me

Sub Get_Macromicro_Charts_JSON_Data_20230913()
Dim UrL As String, URL_a As String, GetXml As Object, Jsondata As Object, DecodeJson, BlueLine, RedLine, datastk As String
Set Jsondata = CreateObject("HtmlFile")
Set GetXml = CreateObject("WinHttp.WinHttpRequest.5.1")

With GetXml
UrL = "https://www.macromicro.me/charts/20069/tw-mtx-long-to-short-ratio-of-individual-player"
URL_a = "https://www.macromicro.me/charts/data/20069"
.Open "GET", UrL, False
.setrequestheader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
.Option(6) = False
.send
Cookie = Split(.GetResponseHeader("Set-Cookie"), ";")(0)
datastk = Split(Split(.responsetext, "data-stk=""")(1), """>")(0)
Debug.Print Cookie, datastk
.Open "GET", URL_a, False
.setrequestheader "Referer", UrL
.setrequestheader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
.setrequestheader "Cookie", Cookie
.setrequestheader "Authorization", "Bearer " & datastk
.send
Set DecodeJson = CallByName(CallByName(Jsondata.JsonParse(.responsetext), "data", VbGet), "c:20069", VbGet)
'台灣-小台指散戶多空比
Set BlueLine = CallByName(CallByName(DecodeJson, "series", VbGet), 0, VbGet)
'台灣 -加權股價指數
Set RedLine = CallByName(CallByName(DecodeJson, "series", VbGet), 1, VbGet)
'==================
Application.ScreenUpdating = False
With Sheets("工作表1")
.Cells.Clear
.Range("a1:d1") = Array("日期", "多空比", "日期", "指數")
'test1
For i = 0 To CallByName(BlueLine, "length", VbGet) - 1
.Cells(i + 2, 1) = CallByName(CallByName(BlueLine, i, VbGet), 0, VbGet)
.Cells(i + 2, 2) = CallByName(CallByName(BlueLine, i, VbGet), 1, VbGet)
Next i
'test2
For i = 0 To CallByName(RedLine, "length", VbGet) - 1
.Cells(i + 2, 3) = CallByName(CallByName(RedLine, i, VbGet), 0, VbGet)
.Cells(i + 2, 4) = CallByName(CallByName(RedLine, i, VbGet), 1, VbGet)
Next i
End With
Application.ScreenUpdating = True
'==================
End With
Set GetXml = Nothing
Set Jsondata = Nothing
Set DecodeJson = Nothing
Set BlueLine = Nothing
Set RedLine = Nothing
End Sub