如何在SpreadSheets中从Yahoo Finance导入历史数据(CSV) [英] How to import historical data (CSV) from Yahoo Finance in SpreadSheets

查看:32
本文介绍了如何在SpreadSheets中从Yahoo Finance导入历史数据(CSV)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试导入APPLE的历史数据(CSV).我在Google Sheet中使用ImportData函数

参考文献:

I try to import historical data (CSV) for APPLE. I use ImportData function in Google Sheet with

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

but the result is "#N/A".

I want to get the CSV because there is 3 decimals. And only 2, on the website.

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

There is a script after to obtain the file : AAPL.csv .

Can you help me ?

解决方案

Unfortunately, in the case of the URL, it seems that IMPORTDATA and IMPORTXML cannot be used. But, fortunately, I confirmed that UrlFetchApp of Google Apps Script can be retrieved the CSV data. So, in this answer, I would like to propose to use Google Apps Script for achieving your goal.

Sample script:

Please copy and paste the following script to the script editor of Google Spreadsheet, and please put =SAMPLE("https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true") to a cell. This script is used as the custom function. By this, the CSV data can be retrieved in the cells.

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

Result:

When above script is used, the following result is obtained.

References:

这篇关于如何在SpreadSheets中从Yahoo Finance导入历史数据(CSV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆