我使用VBA将股票价格导入Excel。昨天(2024 年 9 月 24 日)停止工作。
该方法需要一个似乎不再存在的 CRUM。当请求 CRUM 时,我得到“e html>
现在有人知道解决方案了吗?代码如下。非常感谢!!
最大
Sub getCookieCrumb(crumb As String, cookie As String, validCookieCrumb As Boolean)
Dim i As Integer
Dim str As String
Dim crumbStartPos As Long
Dim crumbEndPos As Long
Dim objRequest
validCookieCrumb = False
'ask for a valid crumb 5 times
For i = 0 To 5 'ask for a valid crumb 5 times
Set objRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
With objRequest
.Open "GET", "https://finance.yahoo.com/quote/AAPL/history?period1=1503558000&period2=1535094000&interval=1wk&filter=history&frequency=1wk", False
.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
.send
.WaitForResponse (10)
crumbStartPos = InStrRev(.ResponseText, """crumb"":""") + 9
crumbEndPos = crumbStartPos + 11
crumb = Mid(.ResponseText, crumbStartPos, crumbEndPos - crumbStartPos)
End With
If Len(crumb) = 11 Then 'a valid crumb is 11 characters long
validCookieCrumb = True
Exit For
End If
Next i
End Sub
我在一年前取消了对 getCookieCrumb 的调用,直到最近它都工作得很好。现在我收到一条消息,提示用户未登录。
如果您找到解决方案,请分享。我会继续努力自己解决。