异常:参数太大:值 Google 脚本
Exception: argument too large: value Google Script
我正在尝试 抓取 一个网站并将值放入缓存中,这样我就不会达到 UrlFetchApp 的每日限制
这是我做的脚本:
/**
* Scrape URL, return whatever you choose with jquery-style selectors.
Dependency: cheeriogs, see https://github.com/fgborges/cheeriogs
*
* @param {url} valid start-url
* @return result (array values)
*
* @customfunction
*/
function scrapercache(url) {
var result = [];
var description;
var options = {
'muteHttpExceptions': true,
'followRedirects': false,
};
var cache = CacheService.getScriptCache();
var properties = PropertiesService.getScriptProperties();
try {
let res = cache.get(url);
if (!res) {
// trim url to prevent (rare) errors
url.toString().trim();
var r = UrlFetchApp.fetch(url, options);
var c = r.getResponseCode();
// check for meta refresh if 200 ok
if (c == 200) {
var html = r.getContentText();
cache.put(url, "cached", 21600);
properties.setProperty(url, html);
var $ = Cheerio.load(html); // make sure this lib is added to your project!
// meta description
if ($('meta[name=description]').attr("content")) {
description = $('meta[name=description]').attr("content").trim();
}
}
result.push([description]);
}
}
catch (error) {
result.push(error.toString());
}
finally {
return result;
}
}
但是当我这样调用函数时:
=scrapercache("https://www.gurufocus.com/term/total_freecashflow/nyse:ABBV/Free-Cash-Flow")
我收到错误消息:
Exception: argument too large: value
有人可以帮助我吗?
谢谢 :)
加布里埃尔
中所写
The maximum length of a key is 250 characters. The maximum amount of data that can be stored per key is 100KB.
如果放入缓存的数据大小超过上述任何限制,错误
Exception: argument too large
显示。在您的情况下,value
超过 100KB。解决方案是根据您的具体需要只缓存必要的数据或根本不缓存。
我正在尝试 抓取 一个网站并将值放入缓存中,这样我就不会达到 UrlFetchApp 的每日限制
这是我做的脚本:
/**
* Scrape URL, return whatever you choose with jquery-style selectors.
Dependency: cheeriogs, see https://github.com/fgborges/cheeriogs
*
* @param {url} valid start-url
* @return result (array values)
*
* @customfunction
*/
function scrapercache(url) {
var result = [];
var description;
var options = {
'muteHttpExceptions': true,
'followRedirects': false,
};
var cache = CacheService.getScriptCache();
var properties = PropertiesService.getScriptProperties();
try {
let res = cache.get(url);
if (!res) {
// trim url to prevent (rare) errors
url.toString().trim();
var r = UrlFetchApp.fetch(url, options);
var c = r.getResponseCode();
// check for meta refresh if 200 ok
if (c == 200) {
var html = r.getContentText();
cache.put(url, "cached", 21600);
properties.setProperty(url, html);
var $ = Cheerio.load(html); // make sure this lib is added to your project!
// meta description
if ($('meta[name=description]').attr("content")) {
description = $('meta[name=description]').attr("content").trim();
}
}
result.push([description]);
}
}
catch (error) {
result.push(error.toString());
}
finally {
return result;
}
}
但是当我这样调用函数时:
=scrapercache("https://www.gurufocus.com/term/total_freecashflow/nyse:ABBV/Free-Cash-Flow")
我收到错误消息:
Exception: argument too large: value
有人可以帮助我吗? 谢谢 :) 加布里埃尔
The maximum length of a key is 250 characters. The maximum amount of data that can be stored per key is 100KB.
如果放入缓存的数据大小超过上述任何限制,错误
Exception: argument too large
显示。在您的情况下,value
超过 100KB。解决方案是根据您的具体需要只缓存必要的数据或根本不缓存。