【问题标题】:UrlFetchApp.fetch() incomplete content on google.comUrlFetchApp.fetch() google.com 上的内容不完整
【发布时间】:2014-10-17 16:42:16
【问题描述】:

我开始使用 Google Apps 脚本编码。

所以我尝试了这个例子:fetch(url)

// The code below logs the HTML code of the Google home page.
 var response = UrlFetchApp.fetch("http://www.google.com/");
 Logger.log(response.getContentText());

我收到的标签来自:

<!doctype html> to <style>

但是没有这些标签:

</head>, <body>, </body> or </html>

这是一个不正确的 Google Apps 脚本示例还是我的错误? 如何从 google.com 响应完整的 HTML 代码?

【问题讨论】:

    标签: html google-apps-script urlfetch


    【解决方案1】:

    Logger.log 自动截断一定长度后显示的字符串。您正在接收整个页面,但只看到日志中的第一部分。

     // The code below logs the HTML code of the Google home page.
     var response = UrlFetchApp.fetch("http://www.google.com/");
     var content = response.getContentText();
     Logger.log(content);
     //log last 1000 chars of content
     Logger.log(content.substr(-1000));
    

    【讨论】:

    • @cameron Roberts。你能告诉我应该使用什么正则表达式来获取标题和 URL 表单 content.subster(-1000)?
    猜你喜欢
    • 2017-09-27
    • 1970-01-01
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多