如何在电子表格中导入雅虎财经的历史数据(CSV)

nom7f22z  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(223)

我尝试为APPLE导入历史数据(CSV)。我在Google工作表中使用ImportData函数
https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true
但结果是"#N/A"。
我想得到的CSV,因为有3位小数。而只有2,在网站上。

=IMPORTXML("https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true")

之后有一个脚本来获取文件:AAPL. csv.
你能帮帮我吗?

rpppsulh

rpppsulh1#

不幸的是,在URL的情况下,IMPORTDATAIMPORTXML似乎无法使用。但幸运的是,我确认了Google Apps Script的UrlFetchApp可以检索CSV数据。因此,在此回答中,我想建议使用Google Apps Script来实现您的目标。

示例脚本:

请将以下脚本复制粘贴到Google Spreadsheet的脚本编辑器中,并将=SAMPLE("https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true")放入单元格中。此脚本用作自定义函数。通过此脚本,可以在单元格中检索CSV数据。

const SAMPLE = url => Utilities.parseCsv(UrlFetchApp.fetch(url).getContentText());

结果:

当使用上述脚本时,将获得以下结果。

参考文献:

相关问题