I am having a spreadsheet which contains a list of URLs. I am trying to search if an URL contains a particular class or not and based on response I will set 0 or 1 in the cell next to it. I have made a script and it does the purpose but I'm experiencing execution timeout error so just want to is there any way I can reduce it's execution time.
here is the code
function ulrFetch(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var class = ss.getRange(1, 5).getValue();
var lr = ss.getLastRow();
var urlList = ss.getRange(3, 8, lr-1).getValues();
var length = urlList.length
for (var i = 0;i<length;i++){
var url = urlList[i];
var response = UrlFetchApp.fetch(url.toString());
var result = response.getContentText();
var index = result.indexOf(class);
if (index > -1){
ss.getRange(i+3, 5).setValue('1');
}
else {
ss.getRange(i+3, 5).setValue('0');
}
}
}
Thanks in Advance!!
length
ofvar length = urlList.length
? I think that in your situation, you can use fetchAll(). fetchAll() can be worked by the asynchronous processing. But because also I think that whenlength
is large, it might not be able to use it. – Tanaike