Excel VBA:如何从雅虎财经网页中删除单个值

问题描述 投票:0回答:1
excel vba
1个回答
0
投票

您可以尝试使用雅虎的

V8 API
,如下所示;

Sub GetBTC()
    Dim URL As String, startDate As Long, endDate As Long, strResponse As String, valBTC As Variant
    
    startDate = DateDiff("s", "1/1/1970", Date)
    endDate = startDate
    
    URL = "https://query1.finance.yahoo.com/v8/finance/chart/BTC-USD?symbol=BTC-USD&period1=" & startDate & "&period2=" & endDate & "&useYfid=true&interval=1d&includePrePost=true&events=div%7Csplit%7Cearn&lang=en-US&region=US&crumb=Mvg42d3eDTb&corsDomain=finance.yahoo.com"
    
    With CreateObject("MSXML2.ServerXMLHTTP")
        .Open "GET", URL, False
        .send
        strResponse = .responseText
    End With
    
    valBTC = Split(Split(strResponse, """regularMarketPrice"":")(1), ",")(0)
    
    MsgBox valBTC
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.