@mvegter/scrapedin 1.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mvegter/scrapedin",
3
- "version": "1.2.0",
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",
@@ -1,5 +1,5 @@
1
1
  const openPage = require('../openPage')
2
- const scrollToPageBottom = require('./scrollToPageBottom')
2
+ const scrollProfileCardsIntoView = require('./scrollProfileCardsIntoView')
3
3
  const seeMoreButtons = require('./seeMoreButtons')
4
4
  const contactInfo = require('./contactInfo')
5
5
  const cleanProfileData = require('./cleanProfileData')
@@ -9,6 +9,8 @@ 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
15
  const findSection = (headingText) => {
14
16
  const sections = document.querySelectorAll('section')
@@ -28,17 +30,11 @@ const extractProfileData = async (page) => {
28
30
  return [...content.querySelectorAll(':scope > div')].filter(d => d.querySelector('p'))
29
31
  }
30
32
 
31
- // Profile top card
32
- const sections = document.querySelectorAll('section')
33
- let topSection = null
34
- for (const s of sections) {
35
- const h2 = s.querySelector('h2')
36
- if (h2 && ['0 notifications', 'Suggested for you', 'Analytics', 'Activity'].includes(h2.textContent.trim())) continue
37
- if (s.textContent.trim().length > 200) { topSection = s; break }
38
- }
39
-
40
33
  const nameH1 = document.querySelector('h1')
41
34
  const profileName = nameH1 ? txt(nameH1) : document.title.replace(' | LinkedIn', '').trim()
35
+
36
+ // Profile top card
37
+ const topSection = [...document.querySelectorAll('section')].find(s => txt(s.querySelector('h2')) === profileName)
42
38
  let headline = ''
43
39
  let location = ''
44
40
  if (topSection) {
@@ -92,28 +88,26 @@ const extractProfileData = async (page) => {
92
88
  link: companyUrl,
93
89
  url: companyUrl,
94
90
  location: '',
95
- description: descEl ? txt(descEl) : '',
91
+ description: multiline(descEl),
96
92
  date: dateRange,
97
93
  date1: dateParts[0] ? dateParts[0].trim() : '',
98
94
  date2: dateParts[1] ? dateParts[1].trim() : ''
99
95
  })
100
96
  })
101
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.
102
100
  const descEl = group.querySelector('[data-testid="expandable-text-box"]')
103
- let dateStr = ''
104
- for (let i = 1; i < allP.length; i++) {
105
- const t = txt(allP[i])
106
- if (t.includes('\u00B7') || /\d{4}/.test(t.split(' ')[0])) { dateStr = t; break }
107
- }
108
- const dateRange = dateStr.split('\u00B7')[0].trim()
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()
109
103
  const dateParts = dateRange.split(' - ')
110
104
  positions.push({
111
- title: txt(allP[3]) || txt(allP[1]),
112
- companyName,
105
+ title: txt(headerPs[0]),
106
+ companyName: txt(headerPs[1]).split('\u00B7')[0].trim(),
113
107
  link: companyUrl,
114
108
  url: companyUrl,
115
- location: txt(allP[2]) || '',
116
- description: descEl ? txt(descEl) : '',
109
+ location: txt(headerPs.slice(3).find(p => txt(p) !== dateParts[1])),
110
+ description: multiline(descEl),
117
111
  date: dateRange,
118
112
  date1: dateParts[0] ? dateParts[0].trim() : '',
119
113
  date2: dateParts[1] ? dateParts[1].trim() : ''
@@ -179,12 +173,13 @@ const extractProfileData = async (page) => {
179
173
  projDivs.forEach(div => {
180
174
  const ps = [...div.querySelectorAll('p')].filter(p => txt(p).length > 0)
181
175
  if (ps.length === 0) return
182
- const descEl = div.querySelector('[data-testid="expandable-text-box"]')
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))
183
178
  const link = div.querySelector('a[href*="http"]')
184
179
  projects.push({
185
180
  name: txt(ps[0]),
186
181
  date: txt(ps[1]) || '',
187
- description: descEl ? txt(descEl) : '',
182
+ description: multiline(descEl),
188
183
  link: link ? link.getAttribute('href') : ''
189
184
  })
190
185
  })
@@ -216,7 +211,7 @@ const extractProfileData = async (page) => {
216
211
  })
217
212
  }
218
213
 
219
- module.exports = async (browser, cookies, url, waitTimeToScrapMs = 500, hasToGetContactInfo = false, puppeteerAuthenticate = undefined) => {
214
+ const scrapeProfile = async (browser, cookies, url, waitTimeToScrapMs = 500, hasToGetContactInfo = false, puppeteerAuthenticate = undefined) => {
220
215
  logger.info(`starting scraping url: ${url}`)
221
216
 
222
217
  const page = await openPage({ browser, cookies, url, puppeteerAuthenticate })
@@ -248,13 +243,13 @@ module.exports = async (browser, cookies, url, waitTimeToScrapMs = 500, hasToGet
248
243
  })
249
244
 
250
245
  logger.info('scrolling page to the bottom')
251
- await scrollToPageBottom(page)
246
+ await scrollProfileCardsIntoView(page)
252
247
 
253
248
  // Wait for lazy-loaded sections to render after scrolling
254
249
  await new Promise((resolve) => { setTimeout(resolve, 2000) })
255
250
 
256
251
  // Scroll again in case new content was loaded
257
- await scrollToPageBottom(page)
252
+ await scrollProfileCardsIntoView(page)
258
253
  await new Promise((resolve) => { setTimeout(resolve, 1000) })
259
254
 
260
255
  await seeMoreButtons.clickAll(page)
@@ -274,3 +269,6 @@ module.exports = async (browser, cookies, url, waitTimeToScrapMs = 500, hasToGet
274
269
  const cleanedProfile = cleanProfileData(rawProfile)
275
270
  return cleanedProfile
276
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 click expandable text buttons (inline expand, not navigation)
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
  })
@@ -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
- }