Skip to content

Instantly share code, notes, and snippets.

@mhawksey
Created August 18, 2011 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhawksey/1155170 to your computer and use it in GitHub Desktop.
Save mhawksey/1155170 to your computer and use it in GitHub Desktop.
Get comment count in Google Apps.t using screen scraping. Used in http://mashe.hawksey.info/2011/08/and-the-most-engaging-ouseful-info-post-is/
function getCommentCount10(){
for (var rowIdx=0; rowIdx < sheet.getLastRow(); rowIdx++){
var rowNum = rowIdx+TITLE_ROW+1;
if (sheet.getRange(rowNum, COM_COL).getValue()==10){
var url = sheet.getRange(rowNum,URL_COL).getValue();
//var url = "http://blog.ouseful.info/2008/10/14/data-scraping-wikipedia-with-google-spreadsheets/"
Utilities.sleep(500);
try {
var options =
{
"method" : "get"
};
var response = UrlFetchApp.fetch(url, options);
if (response.getResponseCode() == 200) {
var responseStr = response.getContentText();
var pattern = /<h3 class="reply">(.*?) Responses<\/h3>/;
var matches = responseStr.match(pattern);
var commentCount = matches[1];
sheet.getRange(rowNum, COM_COL).setValue(commentCount);
}
} catch(e) {
Logger.log(e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment