Skip to content

Instantly share code, notes, and snippets.

@walkergv
Created February 12, 2015 19:00
Show Gist options
  • Save walkergv/e4114305b7967a649deb to your computer and use it in GitHub Desktop.
Save walkergv/e4114305b7967a649deb to your computer and use it in GitHub Desktop.
Scrapes a list of sites and gathers the values of mailto links
function scrapeAndGetEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var array = sheet.getDataRange().getValues();
var emails = [];
var i = 0;
for (i = 0; i < array[0].length; i++){
var URL = array[i][0].toString();
var response = UrlFetchApp.fetch(URL);
var content = response.getContentText("UTF-8");
var regExp = new RegExp("mailto:([a-zA-Z0-9_/-/.]+@strathcona.ca)","gi");
var match;
while (match = regExp.exec(content)) {
// match is now the next match, in array form.
emails.push([match[1]]);
}
}
//ss.insertSheet().setName("results");
var newSheet = ss.getSheetByName("results");
var results = newSheet.getRange(1,1, emails.length, 1);
results.setValues(emails);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment