Skip to content

Instantly share code, notes, and snippets.

@remylagerweij
Created February 22, 2021 20:27
Show Gist options
  • Save remylagerweij/c4ae393577766ce373e524d0f91d11a9 to your computer and use it in GitHub Desktop.
Save remylagerweij/c4ae393577766ce373e524d0f91d11a9 to your computer and use it in GitHub Desktop.
Scraping people from search results on LinkedIn
let people_list = [];
(function(){
const person_naam = '.actor-name';
const person_title = '.subline-level-1';
const person_location = '.subline-level-2';
const person_job_function = '.mt2.t-12.t-black--light.t-normal.search-result__snippets-black';
function getAttribute(person, attribute){
if (person.querySelector(attribute)) {
return person.querySelector(attribute).innerText;
}
return "";
}
function splitJobAndCompany(person, attribute, job_or_company){
if (!person.querySelector(attribute)) {
return ""
}
let temp_job = person.querySelector(attribute).innerText.split("bij");
if (person.querySelector(attribute)) {
if (job_or_company == "job" && temp_job[0]) {
return temp_job[0].replace("Huidig: ", "");
};
if (job_or_company == "company" && temp_job[1]) {
return temp_job[1];
};
}
return "";
};
function getLinkedInUrl(person) {
if(person.querySelector('.search-result__result-link')) {
return person.querySelector('.search-result__result-link').href;
}
return "";
}
function fetchPeople(){
document.querySelectorAll('.search-result__info').forEach(function(person){
person_data = {
"person_name": getAttribute(person, person_naam),
"person_title": getAttribute(person,person_title),
"person_location": getAttribute(person, person_location),
"person_function": splitJobAndCompany(person, person_job_function, "job"),
"person_company": splitJobAndCompany(person, person_job_function, "company"),
"person_linkedinurl": getLinkedInUrl(person)
}
people_list.push(person_data)
});
// console.log(JSON.stringify(people_list));
checkAndClickNext();
}
function checkAndClickNext(){
let pagination_button = document.querySelector('.artdeco-pagination .artdeco-pagination__button--next');
if (!pagination_button.classList.contains("artdeco-button--disabled")) {
pagination_button.click()
setTimeout(function(){
setTimeout(function(){
window.scrollTo(0,document.body.scrollHeight);
setTimeout(function(){
fetchPeople();
}, 2000)
}, 2000);
}, 3000);
} else {
console.log(JSON.stringify(people_list));
}
}
fetchPeople();
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment