Google Apps 脚本 returns 执行日志中需要结果,但电子表格中的单元格为空
Google Apps Script returns desired result in execution log, but cell in spreadsheets is empty
On this spreadsheet,Apps Script returns 正确的结果当我 运行 它时,执行日志正确 returns "202000.0".
但是,当我 运行 单元格中的脚本(在链接的电子表格中以橙色突出显示)时,单元格是空的,有人知道如何解决这个问题吗?
Apps 脚本代码:
function fullTimeEmployees(url) {
var url = 'https://finance.yahoo.com/quote/WBA/profile'
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/root.App.main = ([\s\S\w]+?);\n/)
if (!jsonString || jsonString.length == 1) return;
var data = JSON.parse(jsonString[1].trim())
Logger.log(data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees)
}
此外,有人知道我可以将 .fulltimeEmployees(最后)更改为 returns 公司全名吗?如图所示,以绿色突出显示
问题 1 的答案:
However, when I run the script in a cell (highlighted in orange on the linked spreadsheet), the cell is empty, does anyone know how to fix this by any chance?
在您的脚本中,没有返回任何值。这就是你的问题的原因。所以请修改你的脚本如下。
function fullTimeEmployees(url) {
var url = 'https://finance.yahoo.com/quote/WBA/profile'
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/root.App.main = ([\s\S\w]+?);\n/)
if (!jsonString || jsonString.length == 1) return;
var data = JSON.parse(jsonString[1].trim())
Logger.log(data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees)
return data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees; // Added
}
问题 2 的答案:
Also, does anyone know what I can change .fulltimeEmployees (at the end) to so it returns the full company name? as pictured here, highlighted in green
这样的话,修改如下如何?
发件人:
data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees
收件人:
data.context.dispatcher.stores.QuoteSummaryStore.price.shortName
- 这个的值为
Walgreens Boots Alliance, Inc.
。
On this spreadsheet,Apps Script returns 正确的结果当我 运行 它时,执行日志正确 returns "202000.0".
但是,当我 运行 单元格中的脚本(在链接的电子表格中以橙色突出显示)时,单元格是空的,有人知道如何解决这个问题吗?
Apps 脚本代码:
function fullTimeEmployees(url) {
var url = 'https://finance.yahoo.com/quote/WBA/profile'
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/root.App.main = ([\s\S\w]+?);\n/)
if (!jsonString || jsonString.length == 1) return;
var data = JSON.parse(jsonString[1].trim())
Logger.log(data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees)
}
此外,有人知道我可以将 .fulltimeEmployees(最后)更改为 returns 公司全名吗?如图所示,以绿色突出显示
问题 1 的答案:
However, when I run the script in a cell (highlighted in orange on the linked spreadsheet), the cell is empty, does anyone know how to fix this by any chance?
在您的脚本中,没有返回任何值。这就是你的问题的原因。所以请修改你的脚本如下。
function fullTimeEmployees(url) {
var url = 'https://finance.yahoo.com/quote/WBA/profile'
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/root.App.main = ([\s\S\w]+?);\n/)
if (!jsonString || jsonString.length == 1) return;
var data = JSON.parse(jsonString[1].trim())
Logger.log(data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees)
return data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees; // Added
}
问题 2 的答案:
Also, does anyone know what I can change .fulltimeEmployees (at the end) to so it returns the full company name? as pictured here, highlighted in green
这样的话,修改如下如何?
发件人:
data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees
收件人:
data.context.dispatcher.stores.QuoteSummaryStore.price.shortName
- 这个的值为
Walgreens Boots Alliance, Inc.
。