2

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 ?

Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

3

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.

enter image description here

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • @Stratagenus also note that you won't be able to use that URL with [IMPORTXML](https://support.google.com/docs/answer/3093342?hl=en) because that URL will download the data (it probably runs a request script that returns the downloaded data) and therefore the URL does not contain any XML, HTML, CSV, TSV or RSS feed. – Mateo Randwolf Jan 04 '21 at 08:40