开发者

Finding elements after a URLfetch

开发者 https://www.devze.com 2023-02-26 09:27 出处:网络
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

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;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消