How about this modification? I thought that 720 requests might be able to be used by fetchAll(). So I would like to propose to use fetchAll(). The flow of this modified script is as follows.
- Create requests using
urlList
.
- Retrieve values from URL using fetchAll().
- Create values for putting to Spreadsheet.
- Put the created values to "E3:E".
Modified script :
Please modify as follows.
From :
var urlList = ss.getRange(3, 8, lr-1).getValues();
To :
var urlList = ss.getRange(3, 8, lr - 1 - 1).getValues();
By this modification, the values from row 3 to last row can be retrieved.
And
From :
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');
}
}
To :
var requests = urlList.map(function(e) {return {url: e[0]}});
var res = UrlFetchApp.fetchAll(requests);
var values = res.map(function(e) {return e.getContentText().indexOf(class) > -1 ? ["1"] : ["0"]});
ss.getRange(3, 5, values.length, 1).setValues(values);
Note :
- If an error due to the limitation of fetchAll() occurs, please tell me. I would like to modify the script.
Reference :
If I misunderstand your question, I'm sorry.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…