Can't download data from Yahoo Finance using Quantmod in R

后端 未结 6 1909
挽巷
挽巷 2020-11-28 10:12

I\'m trying to download data from Yahoo using this code:

library(quantmod)
getSymbols(\"WOW\", auto.assign=F)

This has worked for me in the

6条回答
  •  萌比男神i
    2020-11-28 10:45

    I too am encountering this error. A user on mrexcel fourm (jonathanwang003) explains that the new URL uses Unix Timecoding for dates. The updated VBA code would look something like this:

    qurl = "https://query1.finance.yahoo.com/v7/finance/download/" & Symbol
    qurl = qurl & "?period1=" & (StartDate - DateSerial(1970, 1, 1)) * 86400 & _
           "&period2=" & (EndDate - DateSerial(1970, 1, 1)) * 86400 & _
           "&interval=1d&events=history&crumb=" & **Crumb**
    
    QueryQuote:
    With Sheets(Symbol).QueryTables.Add(Connection:="URL;" & qurl, Destination:=Sheets(Symbol).Range("a1"))
        .BackgroundQuery = True
        .TablesOnlyFromHTML = False
        .Refresh BackgroundQuery:=False
        .SaveData = True
    End With
    

    The missing piece here is how to retrieve the "Crumb" field that contains cookie information from the browser. Anyone have any ideas. I found this post, which may help: https://www.mrexcel.com/forum/excel-questions/1001259-when-using-querytables-what-posttext-syntax-click-button-webpage.html (look at last post by john_w).

提交回复
热议问题