Created
March 21, 2026 11:43
-
-
Save SahilMahadwar/4b4a8200835bdefd89f564281301e13e to your computer and use it in GitHub Desktop.
Scrape linkdin
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
| (async () => { | |
| const DELAY_BETWEEN_REQUESTS = 5000; | |
| const SAVE_EVERY = 10; | |
| function sleep(ms) { | |
| return new Promise(res => setTimeout(res, ms)); | |
| } | |
| function waitForResult() { | |
| return new Promise((resolve) => { | |
| const interval = setInterval(() => { | |
| const loading = document.querySelector('.spinner-border'); | |
| const resultCard = document.querySelector('.email-result-card'); | |
| if (!loading && resultCard) { | |
| clearInterval(interval); | |
| resolve(); | |
| } | |
| }, 500); | |
| }); | |
| } | |
| function extractLinkedIn() { | |
| const link = document.querySelector('.social-icons a[href*="linkedin"]'); | |
| return link ? link.href : ''; | |
| } | |
| function setEmailAndSearch(email) { | |
| const input = document.querySelector('#email'); | |
| const form = document.querySelector('#reverse-email-lookup-form'); | |
| input.value = email; | |
| input.dispatchEvent(new Event('input', { bubbles: true })); | |
| form.querySelector('button[type="submit"]').click(); | |
| } | |
| function downloadCSV(data, part = 'final') { | |
| const csv = [ | |
| ['email', 'linkedin'], | |
| ...data.map(row => [row.email, row.linkedin]) | |
| ] | |
| .map(e => e.join(',')) | |
| .join('\n'); | |
| const blob = new Blob([csv], { type: 'text/csv' }); | |
| const url = URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.download = `linkedin_results_${part}.csv`; | |
| a.click(); | |
| URL.revokeObjectURL(url); | |
| } | |
| async function processEmails(emails) { | |
| const results = []; | |
| for (let i = 0; i < emails.length; i++) { | |
| const email = emails[i]; | |
| console.log(`Checking (${i + 1}/${emails.length}):`, email); | |
| try { | |
| setEmailAndSearch(email); | |
| await waitForResult(); | |
| await sleep(1000); | |
| const linkedin = extractLinkedIn(); | |
| results.push({ email, linkedin }); | |
| console.log('β Result:', email, linkedin); | |
| } catch (err) { | |
| console.error('β Error:', email, err); | |
| results.push({ email, linkedin: '' }); | |
| } | |
| // π₯ SAVE EVERY 10 | |
| if ((i + 1) % SAVE_EVERY === 0) { | |
| console.log(`πΎ Saving batch ${i + 1}`); | |
| downloadCSV(results, `batch_${i + 1}`); | |
| } | |
| await sleep(DELAY_BETWEEN_REQUESTS); | |
| } | |
| // Final save | |
| downloadCSV(results, 'final'); | |
| console.log('π DONE'); | |
| } | |
| // File upload | |
| const input = document.createElement('input'); | |
| input.type = 'file'; | |
| input.accept = '.csv'; | |
| input.onchange = async (e) => { | |
| const file = e.target.files[0]; | |
| const text = await file.text(); | |
| const lines = text.split('\n').slice(1); | |
| const emails = lines | |
| .map(l => l.split(',')[0]?.trim()) | |
| .filter(Boolean); | |
| console.log('Loaded emails:', emails.length); | |
| await processEmails(emails); | |
| }; | |
| input.click(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment