The IMPORTHTML()
and IMPORTXML()
functions don't fetch this page for some reason I don't know.
You can use URLFetchApp in Google Apps Script instead.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
function fetch() {
//Replace the "A2" with A1 notation of the cell which you'd like to type the keys
const key = sheet.getRange("A2").getValue();
url = `https://finance.yahoo.com/quote/${key}/key-statistics`;
const response = UrlFetchApp.fetch(url).getContentText();
//We will use Cheerio for HTML parsing
const $ = Cheerio.load(response);
const value = $('fin-streamer[data-field="regularMarketPrice"][data-test="qsp-price"]').text();
//Replace the "B2" with A1 notation of your target cell
sheet.getRange('B2').setValue(value || "Not found!");
}
And my apsscript.json manifest file is as follows:
{
"timeZone": "Europe/Istanbul", //or whatever
"dependencies": {
"libraries": [
{
"userSymbol": "Cheerio",
"version": "14",
"libraryId": "1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0"
}
]
},
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets.currentonly"
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
Here is a working example. When you click on the button it writes the Float value to A2 cell.