谷歌表单错误-一天内调用的服务次数太多:urlpetch



我在Google Sheets中的函数有问题。我每天都会收到这样的错误:;异常:一天内调用的服务次数太多:urlpetch"我在文档中有大约1000个url。我在谷歌寻找解决方案。我发现了一些建议在函数中添加缓存的主题,但我不知道如何做到。有人知道吗?我的功能:

function ImportCeny(url, HTMLClass) { 
var output = ''; 
var fetchedUrl = UrlFetchApp.fetch(url, {muteHttpExceptions: true}); 
if (fetchedUrl) { 
var html = fetchedUrl.getContentText(); 
} 
// Grace period to avoid call limit 
Utilities.sleep(1000); 
var priceposition = html.search(HTMLClass);
return html.slice(priceposition,priceposition + 70).match(/(-d+|d+)(,d+)*(.d+)*/g); 
}

您可以尝试添加一个随机生成的数字,例如6位数字,并在每次调用">UrlFetchApp";

即。;

url=url"?t=458796";

在进行下一次调用之前,您当然可以使用Utilities.sleep()强制程序停止一段时间。然而,使用内置的Cache类(您可以在这里看到文档(更合适,因为它是专门为这些场景设计的。所以,如果你想离开一秒钟,你可以替换:

Utilities.sleep(1000); //In milliseconds

带有

var cache = CacheService.getScriptCache(); //Create a cache instance
cache.put("my_content", html, 1); // In seconds

最新更新