Last active
June 22, 2019 23:23
-
-
Save shakkurcwb/15b2294a22605f011e4541cba9e3fe94 to your computer and use it in GitHub Desktop.
LinkedIn - Script To Collect Emails From Comment List
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
/** | |
* Script to collect emails from comment list on LinkedIn | |
* | |
* 1 - Load the post page (must not be the activity page, but the post page itself - URL like this: /feed/update/*); | |
* 2 - Copy and Paste this code into your Browser Console Tab (press F12 or CTRL+SHIFT+I then click on Console tab. Just paste the code.); | |
* 3 - Press enter to execute the script, and wait until it is finished (could took some time, depends on your clicksLimit param below); | |
* 4 - After the end of execution, a list of all the emails will be presented. Just copy the list and do whatever you want with this. | |
* | |
* This script uses all the tools already in-use by LinkedIn page. There is no external tools in use. | |
* If youre not confident about how it works, read the code. Its very simple and clear. | |
* Feel free to use, share and study this script. | |
* Im not responsible for bad usages. Be responsible, dont be a jerk. | |
* | |
* @author ma.ferreira93@gmail.com | |
*/ | |
var timer; | |
var clicksCount = 0; | |
var clicksLimit = 5; // You can change this - its just a lock to prevent the browser from using too much memory. | |
var speedOfClick = 2000; // You can change this also. 1000ms means 1sec. | |
var listOfFoundedEmails = []; | |
function initScript() { | |
simulateLoadMoreCommentsClick(); | |
timer = setInterval(simulateLoadMoreCommentsClick, speedOfClick); | |
} | |
function simulateLoadMoreCommentsClick() { | |
var button = $("#show_prev"); | |
if (button && clicksCount < clicksLimit) { | |
clicksCount += 1; | |
console.log('Clicking ' + clicksCount); | |
button.click(); | |
scrollPageToBottom(); | |
if (clicksCount > 60) { | |
speedOfClick = speedOfClick + 1500; | |
} | |
} else { | |
clearInterval(timer); | |
console.clear(); | |
extractEmailsFromComments(); | |
console.log(listOfFoundedEmails.join("\n")); | |
} | |
} | |
function scrollPageToBottom() { | |
var n = $(document).height(); | |
$('html, body').animate({ scrollTop: n }, 50); | |
} | |
function extractEmailsFromComments() { | |
var commentsList = document.getElementsByClassName('comments-comments-list')[0]; | |
for (var i = 0; i < commentsList.children.length; i++) { | |
var comment = commentsList.children[i]; | |
if (!comment) continue; | |
var commentContent = comment.getElementsByClassName('comments-comment-item-content-body')[0]; | |
if (!commentContent) continue; | |
var emailsFoundedInComment = extractEmailFromString(commentContent.innerText); | |
if (emailsFoundedInComment && emailsFoundedInComment.length > 0) { | |
for (var j = 0; j < emailsFoundedInComment.length; j++) { | |
var emailSanitized = emailsFoundedInComment[j].toString().toLowerCase(); | |
listOfFoundedEmails.push(emailSanitized); | |
} | |
} | |
} | |
} | |
function extractEmailFromString(text) { | |
return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi); | |
} | |
initScript(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment