Reputation: 2845
I am trying to search for a string in urlfetchapp response using JavaScript indexof but i get error! could you guys tell me what i am doing wrong here and how to look for string in url's source code?
**this is error:**TypeError: Cannot find function indexOf in object
var url = "http://www.bbc.com";
var options =
{
headers : {'Cache-Control' : 'max-age=0'}
};
var response = UrlFetchApp.fetch(url, options)
if(response.indexOf("sun shine")>-1)
{
var myVar="string found";
SpreadsheetApp.getActiveSheet().getRange('a1').setValue(myVar);
}
Upvotes: 1
Views: 1279
Reputation: 10796
UrlFetchApp.fetch returns an HTTPResponse object which doesn't have an indexOf method. If you are trying to parse the content of the webpage you could try the following which returns a string and can be searched.
var response = UrlFetchApp.fetch(url, options).getContentText();
Upvotes: 1