@mvegter/scrapedin 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/login.js +156 -52
- package/src/openPage.js +1 -1
- package/src/profile/profile.js +150 -97
- package/src/profile/scrollProfileCardsIntoView.js +18 -0
- package/src/profile/seeMoreButtons.js +2 -2
- package/src/scrapedin.js +21 -2
- package/test/profile.test.js +158 -0
- package/src/profile/scrollToPageBottom.js +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mvegter/scrapedin",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "linkedin scraper updated for 2025+ website",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"linkedin",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
],
|
|
10
10
|
"main": "src/scrapedin.js",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"lint": "standard --fix 'src/*.js'"
|
|
12
|
+
"lint": "standard --fix 'src/*.js'",
|
|
13
|
+
"test": "node --test test/"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
15
16
|
"type": "git",
|
package/src/login.js
CHANGED
|
@@ -2,69 +2,173 @@ const openPage = require('./openPage')
|
|
|
2
2
|
const logger = require('./logger')(__filename)
|
|
3
3
|
const pkg = require('./package')
|
|
4
4
|
|
|
5
|
+
const ACCEPT_COOKIES_SELECTORS = [
|
|
6
|
+
'button:has-text("Accept")',
|
|
7
|
+
'button:has-text("Alle accepteren")',
|
|
8
|
+
'button[action-type="ACCEPT"]',
|
|
9
|
+
'.cookie-consent-v2__button--accept',
|
|
10
|
+
'#artdeco-global-alert-container button:has-text("Accept")'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
const acceptCookies = async (page) => {
|
|
14
|
+
for (const selector of ACCEPT_COOKIES_SELECTORS) {
|
|
15
|
+
try {
|
|
16
|
+
const btn = await page.$(selector)
|
|
17
|
+
if (btn) {
|
|
18
|
+
await btn.click()
|
|
19
|
+
await new Promise((r) => setTimeout(r, 1000))
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// selector might not exist, try next
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Fallback: find any button with Accept text
|
|
27
|
+
try {
|
|
28
|
+
await page.evaluate(() => {
|
|
29
|
+
const btn = Array.from(document.querySelectorAll('button')).find(
|
|
30
|
+
(b) => b.textContent.trim().toLowerCase() === 'accept'
|
|
31
|
+
)
|
|
32
|
+
if (btn) btn.click()
|
|
33
|
+
})
|
|
34
|
+
await new Promise((r) => setTimeout(r, 1000))
|
|
35
|
+
} catch {
|
|
36
|
+
// ignore
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const fillField = async (page, fieldValue) => {
|
|
41
|
+
// LinkedIn renders two sets of inputs: hidden (CSS-only, not visible) and visible.
|
|
42
|
+
// We find all <input> elements matching the autocomplete attribute, then pick
|
|
43
|
+
// the first one that is actually visible (has non-zero dimensions).
|
|
44
|
+
const autocomplete = fieldValue === 'username webauthn' ? 'username' : 'current-password'
|
|
45
|
+
|
|
46
|
+
const visibleInput = await page.evaluate((auto, val) => {
|
|
47
|
+
const inputs = Array.from(document.querySelectorAll(`input[autocomplete="${auto}"]`))
|
|
48
|
+
for (const input of inputs) {
|
|
49
|
+
const rect = input.getBoundingClientRect()
|
|
50
|
+
if (rect.width > 0 && rect.height > 0) {
|
|
51
|
+
const style = window.getComputedStyle(input)
|
|
52
|
+
if (style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0') {
|
|
53
|
+
input.focus()
|
|
54
|
+
input.value = ''
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false
|
|
60
|
+
}, autocomplete, fieldValue)
|
|
61
|
+
|
|
62
|
+
if (visibleInput) {
|
|
63
|
+
await page.keyboard.type(fieldValue, { delay: 50 })
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const clickSignIn = async (page) => {
|
|
68
|
+
// Find the "Sign in" button, excluding "Sign in with Apple" etc.
|
|
69
|
+
await page.evaluate(() => {
|
|
70
|
+
const buttons = Array.from(document.querySelectorAll('button'))
|
|
71
|
+
const signInBtn = buttons.find(
|
|
72
|
+
(b) => {
|
|
73
|
+
const text = b.textContent.trim().toLowerCase()
|
|
74
|
+
return (text === 'sign in' || text === 'inloggen' || text === 'aanmelden') &&
|
|
75
|
+
!text.includes('apple')
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
if (signInBtn) {
|
|
79
|
+
signInBtn.click()
|
|
80
|
+
return true
|
|
81
|
+
}
|
|
82
|
+
return false
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const LOGGED_IN_PATHS = ['/feed', '/mynetwork', '/in/']
|
|
87
|
+
|
|
5
88
|
module.exports = async (browser, email, password) => {
|
|
6
89
|
const url = 'https://www.linkedin.com/login'
|
|
7
90
|
const page = await openPage({ browser, url })
|
|
8
91
|
logger.info(`logging at: ${url}`)
|
|
9
92
|
|
|
10
|
-
|
|
93
|
+
// Accept cookie consent if present
|
|
94
|
+
await acceptCookies(page)
|
|
95
|
+
await new Promise((r) => setTimeout(r, 1000))
|
|
11
96
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
await
|
|
15
|
-
.then((passwordElement) => passwordElement.type(password))
|
|
97
|
+
// Fill in email field
|
|
98
|
+
await fillField(page, 'username webauthn')
|
|
99
|
+
await new Promise((r) => setTimeout(r, 500))
|
|
16
100
|
|
|
17
|
-
|
|
101
|
+
// Fill in password field
|
|
102
|
+
await fillField(page, 'current-password')
|
|
103
|
+
await new Promise((r) => setTimeout(r, 500))
|
|
18
104
|
|
|
19
|
-
|
|
20
|
-
.then(async () => {
|
|
21
|
-
const currentUrl = page.url()
|
|
22
|
-
if (currentUrl.includes('/feed') || currentUrl.includes('/mynetwork') || currentUrl.includes('/in/')) {
|
|
23
|
-
logger.info('logged in, redirected to: ' + currentUrl)
|
|
24
|
-
await page.close()
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
throw new Error('unexpected redirect: ' + currentUrl)
|
|
28
|
-
})
|
|
29
|
-
.catch(async () => {
|
|
30
|
-
logger.warn('successful login element was not found')
|
|
31
|
-
const emailError = await page.evaluate(() => {
|
|
32
|
-
const e = document.querySelector('div[error-for=username], #error-for-username')
|
|
33
|
-
if (!e) { return false }
|
|
34
|
-
const style = window.getComputedStyle(e)
|
|
35
|
-
return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const passwordError = await page.evaluate(() => {
|
|
39
|
-
const e = document.querySelector('div[error-for=password], #error-for-password')
|
|
40
|
-
if (!e) { return false }
|
|
41
|
-
const style = window.getComputedStyle(e)
|
|
42
|
-
return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const manualChallengeRequested = await page.evaluate(() => {
|
|
46
|
-
const e = document.querySelector('.flow-challenge-content, #challenge, [data-test-id="challenge"]')
|
|
47
|
-
if (!e) { return false }
|
|
48
|
-
const style = window.getComputedStyle(e)
|
|
49
|
-
return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
if (emailError) {
|
|
53
|
-
logger.info('wrong username element found')
|
|
54
|
-
return Promise.reject(new Error(`linkedin: invalid username: ${email}`))
|
|
55
|
-
}
|
|
105
|
+
await clickSignIn(page)
|
|
56
106
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
107
|
+
let hadChallenge = false
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
await page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: 15000 })
|
|
111
|
+
} catch {
|
|
112
|
+
// Navigation timeout is expected — the page may not navigate if already on login
|
|
113
|
+
}
|
|
61
114
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
115
|
+
// Wait for either the feed/mynetwork or challenge page
|
|
116
|
+
const maxWaitMs = 120000
|
|
117
|
+
const start = Date.now()
|
|
118
|
+
let resolved = false
|
|
119
|
+
while (Date.now() - start < maxWaitMs && !resolved) {
|
|
120
|
+
const currentUrl = page.url()
|
|
121
|
+
if (LOGGED_IN_PATHS.some((p) => currentUrl.includes(p))) {
|
|
122
|
+
logger.info('logged in, redirected to: ' + currentUrl)
|
|
123
|
+
resolved = true
|
|
124
|
+
break
|
|
125
|
+
}
|
|
126
|
+
if (currentUrl.includes('/checkpoint')) {
|
|
127
|
+
if (!hadChallenge) {
|
|
128
|
+
logger.warn('2FA challenge detected, please complete the verification in the browser window (waiting up to 2 minutes)...')
|
|
129
|
+
hadChallenge = true
|
|
65
130
|
}
|
|
131
|
+
await new Promise((r) => setTimeout(r, 2000))
|
|
132
|
+
continue
|
|
133
|
+
}
|
|
134
|
+
await new Promise((r) => setTimeout(r, 500))
|
|
135
|
+
}
|
|
66
136
|
|
|
67
|
-
|
|
68
|
-
|
|
137
|
+
if (!resolved) {
|
|
138
|
+
const finalUrl = page.url()
|
|
139
|
+
logger.warn('successful login element was not found, url: ' + finalUrl)
|
|
140
|
+
|
|
141
|
+
const emailError = await page.evaluate(() => {
|
|
142
|
+
const e = document.querySelector('div[error-for=username], #error-for-username')
|
|
143
|
+
if (!e) { return false }
|
|
144
|
+
const style = window.getComputedStyle(e)
|
|
145
|
+
return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
const passwordError = await page.evaluate(() => {
|
|
149
|
+
const e = document.querySelector('div[error-for=password], #error-for-password')
|
|
150
|
+
if (!e) { return false }
|
|
151
|
+
const style = window.getComputedStyle(e)
|
|
152
|
+
return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'
|
|
69
153
|
})
|
|
154
|
+
|
|
155
|
+
if (emailError) {
|
|
156
|
+
logger.info('wrong username element found')
|
|
157
|
+
await page.close()
|
|
158
|
+
return Promise.reject(new Error(`linkedin: invalid username: ${email}`))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (passwordError) {
|
|
162
|
+
logger.info('wrong password element found')
|
|
163
|
+
await page.close()
|
|
164
|
+
return Promise.reject(new Error('linkedin: invalid password'))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
logger.error('could not find any element to retrieve a proper error')
|
|
168
|
+
await page.close()
|
|
169
|
+
return Promise.reject(new Error(`${pkg.name} ${pkg.version} login is not working, please report: ${pkg.bugs.url}`))
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
await page.close()
|
|
173
|
+
return { hadChallenge }
|
|
70
174
|
}
|
package/src/openPage.js
CHANGED
package/src/profile/profile.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const openPage = require('../openPage')
|
|
2
|
-
const
|
|
2
|
+
const scrollProfileCardsIntoView = require('./scrollProfileCardsIntoView')
|
|
3
3
|
const seeMoreButtons = require('./seeMoreButtons')
|
|
4
4
|
const contactInfo = require('./contactInfo')
|
|
5
5
|
const cleanProfileData = require('./cleanProfileData')
|
|
@@ -9,53 +9,46 @@ const logger = require('../logger')(__filename)
|
|
|
9
9
|
const extractProfileData = async (page) => {
|
|
10
10
|
return page.evaluate(() => {
|
|
11
11
|
const txt = (el) => el ? (el.textContent || '').trim() : ''
|
|
12
|
+
// innerText keeps the <br> paragraph breaks LinkedIn uses in descriptions
|
|
13
|
+
const multiline = (el) => el ? (el.innerText || '').trim() : ''
|
|
12
14
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const findSection = (headingText) => {
|
|
16
|
+
const sections = document.querySelectorAll('section')
|
|
17
|
+
for (const s of sections) {
|
|
18
|
+
const h2 = s.querySelector('h2')
|
|
19
|
+
if (h2 && h2.textContent.trim().startsWith(headingText)) return s
|
|
20
|
+
}
|
|
21
|
+
return null
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
// found after the h2 heading: h2.parent.nextSibling > div > div > div
|
|
23
|
-
const getSectionItems = (viewName) => {
|
|
24
|
-
const section = getSection(viewName)
|
|
24
|
+
const getContentDivs = (section) => {
|
|
25
25
|
if (!section) return []
|
|
26
|
-
const ul = section.querySelector('ul')
|
|
27
|
-
if (ul) return [...ul.querySelectorAll(':scope > li')]
|
|
28
26
|
const h2 = section.querySelector('h2')
|
|
29
27
|
if (!h2) return []
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
32
|
-
|
|
33
|
-
return [...itemDivs].filter(d => d.querySelectorAll('p').length > 0)
|
|
28
|
+
const content = h2.parentElement?.nextElementSibling
|
|
29
|
+
if (!content) return []
|
|
30
|
+
return [...content.querySelectorAll(':scope > div')].filter(d => d.querySelector('p'))
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const mainLevel = byViewName('profile-main-level')
|
|
39
|
-
const topSection = mainLevel ? (mainLevel.querySelector('section') || mainLevel.closest('section')) : null
|
|
40
|
-
const nameH2 = topSection ? topSection.querySelector('h2') : null
|
|
41
|
-
const photoImg = document.querySelector('img[src*="profile-displayphoto"]')
|
|
33
|
+
const nameH1 = document.querySelector('h1')
|
|
34
|
+
const profileName = nameH1 ? txt(nameH1) : document.title.replace(' | LinkedIn', '').trim()
|
|
42
35
|
|
|
43
|
-
|
|
36
|
+
// Profile top card
|
|
37
|
+
const topSection = [...document.querySelectorAll('section')].find(s => txt(s.querySelector('h2')) === profileName)
|
|
44
38
|
let headline = ''
|
|
45
39
|
let location = ''
|
|
46
|
-
|
|
47
40
|
if (topSection) {
|
|
48
41
|
const allP = [...topSection.querySelectorAll('p')]
|
|
49
42
|
headline = txt(allP[0])
|
|
50
43
|
for (const p of allP) {
|
|
51
44
|
const t = txt(p)
|
|
52
|
-
if (t.includes(',') && !t.includes('at ') && !t.includes('\
|
|
45
|
+
if (t.includes(',') && !t.includes('at ') && !t.includes('\u00B7') && !t.includes('follow')) {
|
|
53
46
|
location = t
|
|
54
47
|
break
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
|
-
|
|
51
|
+
const photoImg = document.querySelector('img[src*="profile-displayphoto"]')
|
|
59
52
|
const profile = {
|
|
60
53
|
name: profileName,
|
|
61
54
|
headline,
|
|
@@ -64,101 +57,140 @@ const extractProfileData = async (page) => {
|
|
|
64
57
|
imageurl: photoImg ? photoImg.getAttribute('src') || '' : ''
|
|
65
58
|
}
|
|
66
59
|
|
|
67
|
-
// Experience
|
|
60
|
+
// Experience
|
|
68
61
|
const positions = []
|
|
69
|
-
const expSection =
|
|
62
|
+
const expSection = findSection('Experience')
|
|
70
63
|
if (expSection) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
if (!ul) return
|
|
77
|
-
|
|
78
|
-
// Company info is in p tags before the ul
|
|
79
|
-
const allPs = group.querySelectorAll('p')
|
|
80
|
-
const beforeUlPs = []
|
|
81
|
-
for (const p of allPs) {
|
|
82
|
-
if (ul.contains(p)) break
|
|
83
|
-
beforeUlPs.push(p)
|
|
84
|
-
}
|
|
85
|
-
const companyName = txt(beforeUlPs[0])
|
|
64
|
+
const companyGroups = expSection.querySelectorAll('[componentkey^="entity-collection"]')
|
|
65
|
+
companyGroups.forEach(group => {
|
|
66
|
+
const allP = [...group.querySelectorAll('p')].filter(p => txt(p).length > 0)
|
|
67
|
+
if (allP.length === 0) return
|
|
68
|
+
const companyName = txt(allP[0])
|
|
86
69
|
const companyLink = group.querySelector('a[href*="/company/"]')
|
|
87
70
|
const companyUrl = companyLink ? companyLink.getAttribute('href') : ''
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
71
|
+
|
|
72
|
+
const positionLis = group.querySelectorAll('ul > li')
|
|
73
|
+
if (positionLis.length > 0) {
|
|
74
|
+
positionLis.forEach(li => {
|
|
75
|
+
const liPs = [...li.querySelectorAll('p')].filter(p => txt(p).length > 0)
|
|
76
|
+
if (liPs.length === 0) return
|
|
77
|
+
const descEl = li.querySelector('[data-testid="expandable-text-box"]')
|
|
78
|
+
let dateStr = ''
|
|
79
|
+
for (let i = 1; i < liPs.length; i++) {
|
|
80
|
+
const t = txt(liPs[i])
|
|
81
|
+
if (t.includes('\u00B7') || /\d{4}/.test(t)) { dateStr = t; break }
|
|
82
|
+
}
|
|
83
|
+
const dateRange = dateStr.split('\u00B7')[0].trim()
|
|
84
|
+
const dateParts = dateRange.split(' - ')
|
|
85
|
+
positions.push({
|
|
86
|
+
title: txt(liPs[0]),
|
|
87
|
+
companyName,
|
|
88
|
+
link: companyUrl,
|
|
89
|
+
url: companyUrl,
|
|
90
|
+
location: '',
|
|
91
|
+
description: multiline(descEl),
|
|
92
|
+
date: dateRange,
|
|
93
|
+
date1: dateParts[0] ? dateParts[0].trim() : '',
|
|
94
|
+
date2: dateParts[1] ? dateParts[1].trim() : ''
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
} else {
|
|
98
|
+
// Single-role entry lines before the description: title, "company · employment type", "dates · duration",
|
|
99
|
+
// a "Present" badge on current roles, optional location. The skills line follows the description.
|
|
100
|
+
const descEl = group.querySelector('[data-testid="expandable-text-box"]')
|
|
101
|
+
const headerPs = allP.filter(p => !descEl || p.compareDocumentPosition(descEl) & window.Node.DOCUMENT_POSITION_FOLLOWING)
|
|
102
|
+
const dateRange = txt(headerPs[2]).split('\u00B7')[0].trim()
|
|
96
103
|
const dateParts = dateRange.split(' - ')
|
|
97
104
|
positions.push({
|
|
98
|
-
title: txt(
|
|
99
|
-
companyName,
|
|
105
|
+
title: txt(headerPs[0]),
|
|
106
|
+
companyName: txt(headerPs[1]).split('\u00B7')[0].trim(),
|
|
100
107
|
link: companyUrl,
|
|
101
108
|
url: companyUrl,
|
|
102
|
-
location:
|
|
103
|
-
description:
|
|
109
|
+
location: txt(headerPs.slice(3).find(p => txt(p) !== dateParts[1])),
|
|
110
|
+
description: multiline(descEl),
|
|
104
111
|
date: dateRange,
|
|
105
112
|
date1: dateParts[0] ? dateParts[0].trim() : '',
|
|
106
113
|
date2: dateParts[1] ? dateParts[1].trim() : ''
|
|
107
114
|
})
|
|
108
|
-
}
|
|
115
|
+
}
|
|
109
116
|
})
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
// Education
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return
|
|
120
|
+
const educations = []
|
|
121
|
+
const eduSection = findSection('Education')
|
|
122
|
+
const eduDivs = getContentDivs(eduSection)
|
|
123
|
+
eduDivs.forEach(div => {
|
|
124
|
+
const ps = [...div.querySelectorAll('p')].filter(p => txt(p).length > 0)
|
|
125
|
+
if (ps.length === 0) return
|
|
126
|
+
const schoolLink = div.querySelector('a[href*="/school/"]')
|
|
127
|
+
const url = schoolLink ? schoolLink.getAttribute('href') : ''
|
|
128
|
+
const dateStr = txt(ps[2]) || ''
|
|
129
|
+
const dateParts = dateStr.split('\u2013')
|
|
130
|
+
educations.push({
|
|
119
131
|
title: txt(ps[0]),
|
|
120
|
-
degree: txt(ps[1]),
|
|
121
|
-
fieldOfStudy: txt(ps[1]),
|
|
122
|
-
url
|
|
123
|
-
date1:
|
|
124
|
-
date2:
|
|
132
|
+
degree: txt(ps[1]) || '',
|
|
133
|
+
fieldOfStudy: txt(ps[1]) || '',
|
|
134
|
+
url,
|
|
135
|
+
date1: dateParts[0] ? dateParts[0].trim() : '',
|
|
136
|
+
date2: dateParts[1] ? dateParts[1].trim() : '',
|
|
125
137
|
description: ''
|
|
126
|
-
}
|
|
138
|
+
})
|
|
127
139
|
})
|
|
128
140
|
|
|
129
141
|
// Skills
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
const skills = []
|
|
143
|
+
const skillsSection = findSection('Skills')
|
|
144
|
+
if (skillsSection) {
|
|
145
|
+
const allSectionP = [...skillsSection.querySelectorAll('p')].filter(p => txt(p).length > 0)
|
|
146
|
+
for (let i = 0; i < allSectionP.length; i += 2) {
|
|
147
|
+
const name = txt(allSectionP[i])
|
|
148
|
+
if (name && !name.includes('Show all') && !name.includes('Private')) {
|
|
149
|
+
skills.push({ title: name, count: '' })
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
135
153
|
|
|
136
154
|
// Languages
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
155
|
+
const languages = []
|
|
156
|
+
const langSection = findSection('Languages')
|
|
157
|
+
if (langSection) {
|
|
158
|
+
const langDivs = getContentDivs(langSection)
|
|
159
|
+
langDivs.forEach(div => {
|
|
160
|
+
const ps = [...div.querySelectorAll('p')].filter(p => txt(p).length > 0)
|
|
161
|
+
for (let i = 0; i < ps.length; i += 2) {
|
|
162
|
+
const n = txt(ps[i])
|
|
163
|
+
const pr = ps[i + 1] ? txt(ps[i + 1]) : ''
|
|
164
|
+
if (n) languages.push({ name: n, proficiency: pr })
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
}
|
|
142
168
|
|
|
143
169
|
// Projects
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
return
|
|
170
|
+
const projects = []
|
|
171
|
+
const projSection = findSection('Projects')
|
|
172
|
+
const projDivs = getContentDivs(projSection)
|
|
173
|
+
projDivs.forEach(div => {
|
|
174
|
+
const ps = [...div.querySelectorAll('p')].filter(p => txt(p).length > 0)
|
|
175
|
+
if (ps.length === 0) return
|
|
176
|
+
// The project name is wrapped in an expandable text box too
|
|
177
|
+
const descEl = [...div.querySelectorAll('[data-testid="expandable-text-box"]')].find(box => !box.contains(ps[0]) && !ps[0].contains(box))
|
|
178
|
+
const link = div.querySelector('a[href*="http"]')
|
|
179
|
+
projects.push({
|
|
150
180
|
name: txt(ps[0]),
|
|
151
|
-
date: txt(ps[1]),
|
|
152
|
-
description:
|
|
181
|
+
date: txt(ps[1]) || '',
|
|
182
|
+
description: multiline(descEl),
|
|
153
183
|
link: link ? link.getAttribute('href') : ''
|
|
154
|
-
}
|
|
184
|
+
})
|
|
155
185
|
})
|
|
156
186
|
|
|
157
187
|
// Certifications
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
188
|
+
const accomplishments = []
|
|
189
|
+
const certSection = findSection('Licenses')
|
|
190
|
+
const certDivs = getContentDivs(certSection)
|
|
191
|
+
certDivs.forEach(div => {
|
|
192
|
+
const ps = [...div.querySelectorAll('p')].filter(p => txt(p).length > 0)
|
|
193
|
+
if (ps.length > 0) accomplishments.push({ title: txt(ps[0]), count: '', items: [] })
|
|
162
194
|
})
|
|
163
195
|
|
|
164
196
|
return {
|
|
@@ -179,27 +211,45 @@ const extractProfileData = async (page) => {
|
|
|
179
211
|
})
|
|
180
212
|
}
|
|
181
213
|
|
|
182
|
-
|
|
214
|
+
const scrapeProfile = async (browser, cookies, url, waitTimeToScrapMs = 500, hasToGetContactInfo = false, puppeteerAuthenticate = undefined) => {
|
|
183
215
|
logger.info(`starting scraping url: ${url}`)
|
|
184
216
|
|
|
185
217
|
const page = await openPage({ browser, cookies, url, puppeteerAuthenticate })
|
|
186
218
|
|
|
187
|
-
//
|
|
219
|
+
// Check for authwall (expired session)
|
|
220
|
+
const isAuthwall = await page.evaluate(() =>
|
|
221
|
+
window.location.href.includes('/authwall') || document.title.toLowerCase().includes('inschrijven')
|
|
222
|
+
)
|
|
223
|
+
if (isAuthwall) {
|
|
224
|
+
await page.close()
|
|
225
|
+
throw new Error('authwall: LinkedIn session expired, re-authentication required')
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Accept cookie consent if present
|
|
229
|
+
await page.evaluate(() => {
|
|
230
|
+
const btn = Array.from(document.querySelectorAll('button')).find(
|
|
231
|
+
(b) => b.textContent.trim().toLowerCase() === 'accept'
|
|
232
|
+
)
|
|
233
|
+
if (btn) btn.click()
|
|
234
|
+
})
|
|
235
|
+
await new Promise((r) => setTimeout(r, 2000))
|
|
236
|
+
|
|
237
|
+
// Wait for sections to appear (profile content is SDUI rendered)
|
|
188
238
|
await page.waitForFunction(() => {
|
|
189
|
-
return document.
|
|
239
|
+
return document.querySelectorAll('section h2').length > 1
|
|
190
240
|
}, { timeout: 30000 })
|
|
191
241
|
.catch(() => {
|
|
192
242
|
logger.warn('profile content did not fully render in time')
|
|
193
243
|
})
|
|
194
244
|
|
|
195
245
|
logger.info('scrolling page to the bottom')
|
|
196
|
-
await
|
|
246
|
+
await scrollProfileCardsIntoView(page)
|
|
197
247
|
|
|
198
248
|
// Wait for lazy-loaded sections to render after scrolling
|
|
199
249
|
await new Promise((resolve) => { setTimeout(resolve, 2000) })
|
|
200
250
|
|
|
201
251
|
// Scroll again in case new content was loaded
|
|
202
|
-
await
|
|
252
|
+
await scrollProfileCardsIntoView(page)
|
|
203
253
|
await new Promise((resolve) => { setTimeout(resolve, 1000) })
|
|
204
254
|
|
|
205
255
|
await seeMoreButtons.clickAll(page)
|
|
@@ -219,3 +269,6 @@ module.exports = async (browser, cookies, url, waitTimeToScrapMs = 500, hasToGet
|
|
|
219
269
|
const cleanedProfile = cleanProfileData(rawProfile)
|
|
220
270
|
return cleanedProfile
|
|
221
271
|
}
|
|
272
|
+
|
|
273
|
+
module.exports = scrapeProfile
|
|
274
|
+
module.exports.extractProfileData = extractProfileData
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const logger = require('../logger')(__filename)
|
|
2
|
+
|
|
3
|
+
const TIMEOUT_AFTER_SCROLL = 1200
|
|
4
|
+
|
|
5
|
+
// The profile scrolls inside an inner container, so scrolling the window never triggers the lazily rendered cards.
|
|
6
|
+
module.exports = async (page) => {
|
|
7
|
+
const cardIds = await page.evaluate(() => [...document.querySelectorAll('[id^="profileCards"]')].map(e => e.id))
|
|
8
|
+
if (cardIds.length === 0) {
|
|
9
|
+
logger.warn('no profile cards found')
|
|
10
|
+
return
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
for (const id of cardIds) {
|
|
14
|
+
await page.evaluate((id) => document.getElementById(id).scrollIntoView({ block: 'center' }), id)
|
|
15
|
+
await new Promise(resolve => setTimeout(resolve, TIMEOUT_AFTER_SCROLL))
|
|
16
|
+
}
|
|
17
|
+
logger.info(`scrolled ${cardIds.length} profile cards into view`)
|
|
18
|
+
}
|
|
@@ -3,8 +3,8 @@ const logger = require('../logger')(__filename)
|
|
|
3
3
|
const clickAll = async (page) => {
|
|
4
4
|
const clicked = await page.evaluate(() => {
|
|
5
5
|
let count = 0
|
|
6
|
-
// Only
|
|
7
|
-
const expandButtons = document.querySelectorAll('[data-testid="expandable-text-button"]')
|
|
6
|
+
// Only inline expand buttons inside profile cards: the same button on an activity post navigates to that post
|
|
7
|
+
const expandButtons = document.querySelectorAll('[id^="profileCards"] [data-testid="expandable-text-button"]')
|
|
8
8
|
expandButtons.forEach(btn => { btn.click(); count++ })
|
|
9
9
|
return count
|
|
10
10
|
})
|
package/src/scrapedin.js
CHANGED
|
@@ -4,7 +4,22 @@ const profile = require('./profile/profile')
|
|
|
4
4
|
const company = require('./company/company')
|
|
5
5
|
const logger = require('./logger')(__filename)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const saveBrowserCookies = async (browser, cookiesPath) => {
|
|
8
|
+
if (!cookiesPath) return
|
|
9
|
+
try {
|
|
10
|
+
const pages = await browser.pages()
|
|
11
|
+
if (pages.length > 0) {
|
|
12
|
+
const pageCookies = await pages[0].cookies()
|
|
13
|
+
const fs = require('fs')
|
|
14
|
+
fs.writeFileSync(cookiesPath, JSON.stringify(pageCookies, null, 2))
|
|
15
|
+
logger.info('cookies saved to: ' + cookiesPath)
|
|
16
|
+
}
|
|
17
|
+
} catch (e) {
|
|
18
|
+
logger.warn('failed to save cookies: ' + e.message)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = async ({ cookies, email, password, isHeadless, hasToLog, hasToGetContactInfo, cookiesPath, puppeteerArgs, puppeteerAuthenticate, endpoint } = { isHeadless: true, hasToLog: false }) => {
|
|
8
23
|
if (!hasToLog) {
|
|
9
24
|
logger.stopLogging()
|
|
10
25
|
}
|
|
@@ -26,7 +41,11 @@ module.exports = async ({ cookies, email, password, isHeadless, hasToLog, hasToG
|
|
|
26
41
|
logger.info('email and password was provided, we\'re going to login...')
|
|
27
42
|
|
|
28
43
|
try {
|
|
29
|
-
await login(browser, email, password, logger)
|
|
44
|
+
const loginResult = await login(browser, email, password, logger)
|
|
45
|
+
// Only save cookies if login fully completed (no 2FA challenge)
|
|
46
|
+
if (loginResult && !loginResult.hadChallenge && cookiesPath) {
|
|
47
|
+
await saveBrowserCookies(browser, cookiesPath)
|
|
48
|
+
}
|
|
30
49
|
} catch (e) {
|
|
31
50
|
if (!endpoint) {
|
|
32
51
|
await browser.close()
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const { test, before, after } = require('node:test')
|
|
2
|
+
const assert = require('node:assert/strict')
|
|
3
|
+
const puppeteer = require('puppeteer')
|
|
4
|
+
const { extractProfileData } = require('../src/profile/profile')
|
|
5
|
+
const scrollProfileCardsIntoView = require('../src/profile/scrollProfileCardsIntoView')
|
|
6
|
+
const seeMoreButtons = require('../src/profile/seeMoreButtons')
|
|
7
|
+
|
|
8
|
+
let browser
|
|
9
|
+
|
|
10
|
+
before(async () => { browser = await puppeteer.launch() })
|
|
11
|
+
after(async () => { await browser.close() })
|
|
12
|
+
|
|
13
|
+
const extractPositions = async (experienceHtml) => {
|
|
14
|
+
const page = await browser.newPage()
|
|
15
|
+
await page.setContent(`
|
|
16
|
+
<h1>Test Person</h1>
|
|
17
|
+
<section><h2>Experience</h2><div>${experienceHtml}</div></section>
|
|
18
|
+
`)
|
|
19
|
+
const { positions } = await extractProfileData(page)
|
|
20
|
+
await page.close()
|
|
21
|
+
return positions
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test('single-role entry maps title, company, date and location', async () => {
|
|
25
|
+
const positions = await extractPositions(`
|
|
26
|
+
<div componentkey="entity-collection-1">
|
|
27
|
+
<a href="https://www.linkedin.com/company/12345/">
|
|
28
|
+
<p>Software Engineer</p>
|
|
29
|
+
<p>Acme Corp · Full-time</p>
|
|
30
|
+
<p>Jun 2026 - Present · 6 mos</p>
|
|
31
|
+
</a>
|
|
32
|
+
<p>Present</p>
|
|
33
|
+
<p>Springfield, Oregon, United States</p>
|
|
34
|
+
<div data-testid="expandable-text-box"><p>Building the platform.</p></div>
|
|
35
|
+
<p>Java and +3 skills</p>
|
|
36
|
+
</div>
|
|
37
|
+
`)
|
|
38
|
+
|
|
39
|
+
assert.deepEqual(positions, [{
|
|
40
|
+
title: 'Software Engineer',
|
|
41
|
+
companyName: 'Acme Corp',
|
|
42
|
+
link: 'https://www.linkedin.com/company/12345/',
|
|
43
|
+
url: 'https://www.linkedin.com/company/12345/',
|
|
44
|
+
location: 'Springfield, Oregon, United States',
|
|
45
|
+
description: 'Building the platform.',
|
|
46
|
+
date: 'Jun 2026 - Present',
|
|
47
|
+
date1: 'Jun 2026',
|
|
48
|
+
date2: 'Present'
|
|
49
|
+
}])
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('single-role entry without location leaves location empty', async () => {
|
|
53
|
+
const positions = await extractPositions(`
|
|
54
|
+
<div componentkey="entity-collection-1">
|
|
55
|
+
<p>Intern</p>
|
|
56
|
+
<p>Example BV</p>
|
|
57
|
+
<p>Feb 2019 - Jun 2019 · 5 mos</p>
|
|
58
|
+
<div data-testid="expandable-text-box"><p>Automation work.</p></div>
|
|
59
|
+
</div>
|
|
60
|
+
`)
|
|
61
|
+
|
|
62
|
+
assert.equal(positions[0].title, 'Intern')
|
|
63
|
+
assert.equal(positions[0].companyName, 'Example BV')
|
|
64
|
+
assert.equal(positions[0].date, 'Feb 2019 - Jun 2019')
|
|
65
|
+
assert.equal(positions[0].location, '')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('top card is the section headed by the profile name', async () => {
|
|
69
|
+
const page = await browser.newPage()
|
|
70
|
+
await page.setContent(`
|
|
71
|
+
<title>Test Person | LinkedIn</title>
|
|
72
|
+
<section><h2>People you may know</h2>${'<p>Other Member</p><p>Engineer at Somewhere, Utrecht</p>'.repeat(10)}</section>
|
|
73
|
+
<section><h2>Test Person</h2><p>Software Engineer at Acme Corp</p><p>Springfield, Oregon, United States</p></section>
|
|
74
|
+
`)
|
|
75
|
+
const { profile } = await extractProfileData(page)
|
|
76
|
+
await page.close()
|
|
77
|
+
|
|
78
|
+
assert.equal(profile.name, 'Test Person')
|
|
79
|
+
assert.equal(profile.headline, 'Software Engineer at Acme Corp')
|
|
80
|
+
assert.equal(profile.location, 'Springfield, Oregon, United States')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('profile cards rendered lazily inside an inner scroll container get loaded', async () => {
|
|
84
|
+
const page = await browser.newPage()
|
|
85
|
+
await page.setViewport({ width: 800, height: 600 })
|
|
86
|
+
await page.setContent(`
|
|
87
|
+
<style>html, body { margin: 0; height: 100%; overflow: hidden } main { height: 100%; overflow: auto }</style>
|
|
88
|
+
<main>
|
|
89
|
+
<div style="height: 5000px"></div>
|
|
90
|
+
<div id="profileCardsExperienceOnlytest"></div>
|
|
91
|
+
</main>
|
|
92
|
+
<script>
|
|
93
|
+
const card = document.getElementById('profileCardsExperienceOnlytest')
|
|
94
|
+
new IntersectionObserver(([entry]) => {
|
|
95
|
+
if (entry.isIntersecting) card.innerHTML = '<section><h2>Experience</h2></section>'
|
|
96
|
+
}).observe(card)
|
|
97
|
+
</script>
|
|
98
|
+
`)
|
|
99
|
+
await scrollProfileCardsIntoView(page)
|
|
100
|
+
const headings = await page.evaluate(() => [...document.querySelectorAll('section h2')].map(h => h.textContent))
|
|
101
|
+
await page.close()
|
|
102
|
+
|
|
103
|
+
assert.deepEqual(headings, ['Experience'])
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('show-more clicks stay inside profile cards and never open activity posts', async () => {
|
|
107
|
+
const page = await browser.newPage()
|
|
108
|
+
await page.setContent(`
|
|
109
|
+
<section><h2>Activity</h2>
|
|
110
|
+
<button data-testid="expandable-text-button" onclick="document.title = 'navigated to post'">more</button>
|
|
111
|
+
</section>
|
|
112
|
+
<div id="profileCardsExperienceOnlytest">
|
|
113
|
+
<section><h2>Experience</h2>
|
|
114
|
+
<button data-testid="expandable-text-button" onclick="this.textContent = 'expanded'">more</button>
|
|
115
|
+
</section>
|
|
116
|
+
</div>
|
|
117
|
+
`)
|
|
118
|
+
await seeMoreButtons.clickAll(page)
|
|
119
|
+
const result = await page.evaluate(() => ({
|
|
120
|
+
title: document.title,
|
|
121
|
+
experienceButton: document.querySelector('#profileCardsExperienceOnlytest button').textContent
|
|
122
|
+
}))
|
|
123
|
+
await page.close()
|
|
124
|
+
|
|
125
|
+
assert.deepEqual(result, { title: '', experienceButton: 'expanded' })
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('description keeps paragraph breaks', async () => {
|
|
129
|
+
const positions = await extractPositions(`
|
|
130
|
+
<div componentkey="entity-collection-1">
|
|
131
|
+
<p>Software Engineer</p>
|
|
132
|
+
<p>Acme Corp · Full-time</p>
|
|
133
|
+
<p>Jun 2026 - Present · 6 mos</p>
|
|
134
|
+
<p><span data-testid="expandable-text-box">First paragraph.<br><br>Second paragraph.</span></p>
|
|
135
|
+
</div>
|
|
136
|
+
`)
|
|
137
|
+
|
|
138
|
+
assert.equal(positions[0].description, 'First paragraph.\n\nSecond paragraph.')
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('project description is the text box after the project name', async () => {
|
|
142
|
+
const page = await browser.newPage()
|
|
143
|
+
await page.setContent(`
|
|
144
|
+
<h1>Test Person</h1>
|
|
145
|
+
<section><div><h2>Projects</h2></div><div>
|
|
146
|
+
<div>
|
|
147
|
+
<p><span data-testid="expandable-text-box">Example Project</span></p>
|
|
148
|
+
<p>Feb 2020 – Jun 2020</p>
|
|
149
|
+
<p><span data-testid="expandable-text-box">A project description.</span></p>
|
|
150
|
+
</div>
|
|
151
|
+
</div></section>
|
|
152
|
+
`)
|
|
153
|
+
const { projects } = await extractProfileData(page)
|
|
154
|
+
await page.close()
|
|
155
|
+
|
|
156
|
+
assert.equal(projects[0].name, 'Example Project')
|
|
157
|
+
assert.equal(projects[0].description, 'A project description.')
|
|
158
|
+
})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const logger = require('../logger')(__filename)
|
|
2
|
-
|
|
3
|
-
module.exports = async (page) => {
|
|
4
|
-
const MAX_TIMES_TO_SCROLL = 25
|
|
5
|
-
const TIMEOUT_BETWEEN_SCROLLS = 500
|
|
6
|
-
|
|
7
|
-
for (let i = 0; i < MAX_TIMES_TO_SCROLL; i++) {
|
|
8
|
-
await page.evaluate(() => window.scrollBy(0, window.innerHeight))
|
|
9
|
-
|
|
10
|
-
const hasReachedEnd = await page.evaluate(() => {
|
|
11
|
-
return (window.innerHeight + window.scrollY) >= (document.body.scrollHeight - 200)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
if (hasReachedEnd) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
await new Promise(resolve => setTimeout(resolve, TIMEOUT_BETWEEN_SCROLLS))
|
|
19
|
-
logger.info(`scrolling to page bottom (${i + 1})`)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
logger.warn('page bottom not found')
|
|
23
|
-
}
|