问题
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