UrlFetchApp.fetch()在google.com上的不完整内容 [英] UrlFetchApp.fetch() incomplete content on google.com

查看:118
本文介绍了UrlFetchApp.fetch()在google.com上的不完整内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm starting with Google Apps Script coding.

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

So I tried this example: 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());

我收到以下代码:

I'm receiving the tags from:

<!doctype html> to <style>

但没有这些标签:

But there aren't these tags:

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

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

Is it an incorrect Google Apps Script example or is it a mistake on my part? How can I response the complete HTML code from google.com?

推荐答案

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

Logger.log automatically truncates the strings displayed after a certain length. You are receiving the entire page, but only seeing the first part in the 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));

这篇关于UrlFetchApp.fetch()在google.com上的不完整内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆