[英]How to import historical data (CSV) from Yahoo Finance in SpreadSheets
I try to import historical data (CSV) for APPLE.我尝试为 APPLE 导入历史数据 (CSV)。 I use ImportData function in Google Sheet with我在 Google Sheet 中使用 ImportData function
https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true 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".但结果是“#N/A”。
I want to get the CSV because there is 3 decimals.我想得到 CSV 因为有 3 个小数。 And only 2, on the website.而且只有 2 个,在网站上。
=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.获取文件后有一个脚本:AAPL.csv。
Can you help me?你能帮助我吗?
Unfortunately, in the case of the URL, it seems that IMPORTDATA
and IMPORTXML
cannot be used.不幸的是,在 URL 的情况下,似乎无法使用IMPORTDATA
和IMPORTXML
。 But, fortunately, I confirmed that UrlFetchApp
of Google Apps Script can be retrieved the CSV data.但是,幸运的是,我确认 Google Apps Script 的UrlFetchApp
可以检索到 CSV 数据。 So, in this answer, I would like to propose to use Google Apps Script for achieving your goal.因此,在这个答案中,我想建议使用 Google Apps 脚本来实现您的目标。
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.请将以下脚本复制并粘贴到 Google 电子表格的脚本编辑器中,请输入=SAMPLE("https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1577982443&period2=1609604843&interval=1d&events=history&includeAdjustedClose=true")
到一个单元格。 This script is used as the custom function.此脚本用作自定义 function。 By this, the CSV data can be retrieved in the cells.这样,可以在单元格中检索 CSV 数据。
const SAMPLE = url => Utilities.parseCsv(UrlFetchApp.fetch(url).getContentText());
When above script is used, the following result is obtained.使用上述脚本时,会得到以下结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.