Created
August 8, 2011 14:39
-
-
Save mhawksey/1131870 to your computer and use it in GitHub Desktop.
Ping a Google Spreadsheet of urls. Used in http://mashe.hawksey.info/2011/08/open-data-equals-open-scrutiny-but-doesnt-always-equal-all-of-the-answer/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testUrl(){ | |
var doc = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = doc.getSheetByName("PIMS"); | |
var data = sheet.getRange(2,5,sheet.getLastRow(),1).getValues(); | |
for (var i = 0; i < data.length; i++){ | |
var responseCode = "-"; | |
if (data[i][0].substring(0,4)=="http"){ | |
try | |
{ | |
var response = UrlFetchApp.fetch(data[i][0]); | |
responseCode = response.getResponseCode(); | |
} | |
catch (e) | |
{ | |
responseCode = e.message; | |
Logger.log(responseCode); | |
if (responseCode.indexOf("404.")>0){ | |
responseCode = "404"; | |
}else if (responseCode.indexOf("403.")>0){ | |
responseCode = "403"; | |
}else if (responseCode.indexOf("503.")>0){ | |
responseCode = "503"; | |
}else if (responseCode.indexOf("500.")>0){ | |
responseCode = "500"; | |
} | |
else if (responseCode.indexOf("590.")>0){ | |
responseCode = "590"; | |
} | |
} | |
sheet.getRange(i+2,6).setValue(responseCode); | |
} | |
} | |
} |
That's awesome!
One can also use this add-on to find HTTP status code in a Google sheet - https://chrome.google.com/webstore/detail/seomango/oigecakbpjpkahfaeblingmgdhnjiknc?hl=en
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very interesting, is there a possibility of
ping IP
response?i.e. ICMP, not HTTP