Created
February 12, 2015 19:00
-
-
Save walkergv/e4114305b7967a649deb to your computer and use it in GitHub Desktop.
Scrapes a list of sites and gathers the values of mailto links
This file contains hidden or 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 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_/-/.][email protected])","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