Created
August 18, 2011 20:52
-
-
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/
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 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