【问题标题】:Getting data from another url in Appscript从 Appscript 中的另一个 url 获取数据
【发布时间】:2020-07-08 01:34:48
【问题描述】:

我正在尝试从site 中抓取数据。获取产品信息的request url 正确显示在浏览器中。但没有得到UrlFetchApp。我的代码如下

function myFunction() {  
  var coles_url = "https://shop.coles.com.au/search/resources/store/20520/productview/bySeoUrlKeyword/mutti-tomato-passata-2349503p?catalogId=12064";
  Logger.log(jsonInitColes(coles_url));
  
}

function jsonInitColes(url){
   var options =
  {
   "method"  : "GET",   
   "followRedirects" : true,
   "muteHttpExceptions": true
    };
   var response = UrlFetchApp.fetch(url,options);
   var content = response.getContentText();
   return content; 
}

但我得到的是以下 HTML 而不是数据 status_code is 429(Too many requests)

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="about:blank">
</head>
<body>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/j.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/f.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint/script/kpf.js?url=/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint&token=c3436f36-e3c3-a537-25f3-bedc8592f189"></script>
</body>
</html>

浏览器检查请求

【问题讨论】:

    标签: google-apps-script web-scraping http-status-code-429


    【解决方案1】:

    答案:

    对此你无能为力。

    更多信息:

    Google Apps 脚本在云中运行,因此您的提取将来自一些未指定的 Google IP。

    想象一下有多少用户在使用 Google Apps 脚本。在这些用户中,有多少人试图从相同的站点和服务器获取信息。在将UrlFetchApp 用于不需要身份验证的外部端点时,Too many Requests 是一个不幸的常见错误

    如果您收到 Too many requests 错误并且您没有进行快速重试,则可能是来自云中所有其他 Apps 脚本脚本的请求过多,向同一服务器发出请求。对此你无能为力。

    【讨论】:

      猜你喜欢
      • 2019-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      • 2022-01-08
      • 2012-10-22
      相关资源
      最近更新 更多