UrlFetchApp.fetch() incomplete content on google.com

一世执手 提交于 2019-12-22 12:28:09

问题


I'm starting with Google Apps Script coding.

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>

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?


回答1:


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));


来源:https://stackoverflow.com/questions/26429674/urlfetchapp-fetch-incomplete-content-on-google-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!