简体   繁体   English

如何在电子表格中从 Yahoo Finance 导入历史数据 (CSV)

[英]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 的情况下,似乎无法使用IMPORTDATAIMPORTXML 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 脚本来实现您的目标。

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.请将以下脚本复制并粘贴到 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());

Result:结果:

When above script is used, the following result is obtained.使用上述脚本时,会得到以下结果。

在此处输入图像描述

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从雅虎财经的统计页面中获取实时企业价值/EBITDA 和每股账面价值 (mrq)? (谷歌表格) - How do I scrape the live Enterprise Value/EBITDA & Book Value Per Share (mrq) from Yahoo Finance's Statistics page? (Google Sheets) 雅虎金融商品股票报价PHP - Yahoo Finance Commodity Stock Quote PHP R导入具有功能的CSV数据 - R import csv data with function 如何从csv文件中分离数据 - how to separate data from a csv file 当我尝试从 csv 文件导入数据时,我的 function 返回空列表 - My function returns empty list while I try to import data from csv file Python:如何将.csv文件中的信息作为包含元组的列表导入python? - Python: How to import information from a .csv file to python as a list with tuples inside? python 如何使用 csv 文件中的数据运行函数 - python How to run a function using data from csv file 如何使用 R 将某些数据从一个 csv 文件复制到另一个 csv 文件? - How can I copy certain data from one csv file to another csv file using R? 如何将范围传递给 Google 电子表格中的自定义函数? - How to pass a range into a custom function in Google Spreadsheets? 从文件中读取 CSV 数据到字典中 - Reading CSV data from a file into a dictionary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM