What would be the best way to parse an HTML string after a URLfetch ? If we find element it would return True else False, right now I'm using this , but I don't think I'm on the right path since it's already erroring out ! This is running as a script in a google spreadsheet .
function amazo开发者_Python百科n() {
var response = UrlFetchApp.fetch("http://www.amazon.com/");
var text = response.getContentText();
var result = text.find("kindle");
return result
}
You could try something like this, which would return false if the string "kindle" isn't present or true if it is present at least once.
function amazon() {
var response = UrlFetchApp.fetch("http://www.amazon.com/");
var text = response.getContentText();
var result = text.search("kindle");
if (result == -1) {
return false;
} else {
return true;
}
}
精彩评论