Created
June 7, 2024 05:57
-
-
Save HarryZ10/26e0d8fd591e9a9b0a1bed2e827da54a to your computer and use it in GitHub Desktop.
Organize Your LinkedIn Connection Invites
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
function grabContent() { | |
const invitationCards = document.querySelectorAll('.invitation-card'); | |
const data = Array.from(invitationCards).map(card => { | |
// Get the name | |
const nameElement = card.querySelector('.invitation-card__tvm-title a strong a'); | |
const name = nameElement ? nameElement.textContent.trim() : ''; | |
// Get the content | |
const contentElement = card.querySelector('.lt-line-clamp__raw-line'); | |
const content = contentElement ? contentElement.textContent.trim() : ''; | |
// Get the link | |
const linkElement = card.querySelector('.invitation-card__tvm-title a'); | |
const link = linkElement ? linkElement.href : ''; | |
// Get the header | |
const headerElement = card.querySelector('.invitation-card__subtitle'); | |
const header = headerElement ? headerElement.textContent.trim() : ''; | |
return { name, header, content, link }; | |
}); | |
// COMMENT this out if you just want the object for API purposes? | |
const csv = [ | |
...data.map(item => `"${item.name}","${item.header}",${''},"${item.content}",${item.link}`), | |
].join('\n'); | |
console.log(csv); | |
} | |
async function run() { | |
const totalPages = 5; | |
async function clickPaginationButton(page) { | |
const button = document.querySelector(`button[aria-label="Page ${page}"]`); | |
if (button) { | |
button.click(); | |
await new Promise(resolve => setTimeout(resolve, 5000)); | |
} | |
} | |
// Loop through each page | |
for (let page = 1; page <= totalPages; page++) { | |
await clickPaginationButton(page); | |
// Click all "See more" links | |
const connects = document.querySelectorAll('.lt-line-clamp__more'); | |
connects.forEach(function(link) { | |
if (!link.closest('span').querySelector('.lt-line-clamp__less')) { | |
link.click(); | |
} | |
}); | |
await new Promise(resolve => setTimeout(resolve, 5000)); | |
grabContent(); | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment