Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Employee Harvesting from Linked In (companion code to blog post)
const linkedinEmail = '*******';
const linkedinPassword = '*******';
const companyName = 'CHANGE ME';
const extraFilter = 'change me (or set to null)';
const maxPages = 2;
////////
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
const encodedCompanyName = encodeURIComponent(companyName)
// Login
await page.goto('https://www.linkedin.com');
await page.waitForSelector('#login-email');
await page.type('#login-email', linkedinEmail);
await page.type('#login-password', linkedinPassword);
await page.click('#login-submit');
await page.waitFor(5000);
let users = [];
for (let pageNumber=1; pageNumber <= maxPages; pageNumber++){
await page.goto(`https://www.linkedin.com/search/results/all/?keywords=${encodedCompanyName}&page=${pageNumber}`);
await page.waitForSelector('#nav-settings__dropdown-trigger > img');
await page.evaluate(()=>{
window.scrollTo(0,document.body.scrollHeight);
});
await page.waitFor(5000);
let results = await page.evaluate( (extraFilter)=>{
let pageUsers = [];
let pagePositions = [];
let pageResults = [];
Array.from(document.getElementsByClassName('actor-name')).forEach( el => pageUsers.push(el.textContent));
Array.from(document.querySelectorAll('span[dir="ltr"]')).forEach( el => pagePositions.push(el.innerHTML));
let innerCounter = 0;
for (let counter = 0; counter < pageUsers.length; counter++){
const fullPosition = `${pagePositions[innerCounter]}, ${pagePositions[innerCounter+1]}`;
if (extraFilter && fullPosition.toLowerCase().indexOf(extraFilter.toLowerCase()) >= 0){
pageResults.push(`${pageUsers[counter]} : ${fullPosition}`);
} else if (extraFilter===null){
pageResults.push(`${pageUsers[counter]} : ${fullPosition}`);
}
innerCounter = innerCounter +2;
}
return pageResults;
}, extraFilter);
users = users.concat(results);
}
console.log(users);
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment