@jackwener/opencli 1.8.0 → 1.8.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/README.md +8 -49
- package/README.zh-CN.md +8 -52
- package/cli-manifest.json +1796 -191
- package/clis/_atlassian/shared.js +577 -0
- package/clis/_atlassian/shared.test.js +170 -0
- package/clis/bilibili/comment.js +125 -0
- package/clis/bilibili/comment.test.js +153 -0
- package/clis/bilibili/comments.js +116 -21
- package/clis/bilibili/comments.test.js +77 -18
- package/clis/bilibili/subtitle.js +76 -31
- package/clis/bilibili/subtitle.test.js +156 -9
- package/clis/bilibili/utils.js +63 -5
- package/clis/bilibili/utils.test.js +45 -1
- package/clis/chess/analyze.js +35 -0
- package/clis/chess/analyze.test.js +79 -0
- package/clis/chess/game.js +114 -0
- package/clis/chess/game.test.js +178 -0
- package/clis/chess/games.js +67 -0
- package/clis/chess/games.test.js +164 -0
- package/clis/chess/stats.js +32 -0
- package/clis/chess/stats.test.js +79 -0
- package/clis/chess/utils.js +170 -0
- package/clis/chess/utils.test.js +230 -0
- package/clis/confluence/commands.test.js +195 -0
- package/clis/confluence/create.js +39 -0
- package/clis/confluence/page.js +23 -0
- package/clis/confluence/search.js +34 -0
- package/clis/confluence/shared.js +173 -0
- package/clis/confluence/update.js +38 -0
- package/clis/douyin/hashtag.js +84 -23
- package/clis/douyin/hashtag.test.js +113 -0
- package/clis/geogebra/add-circle.js +46 -0
- package/clis/geogebra/add-line.js +35 -0
- package/clis/geogebra/add-point.js +27 -0
- package/clis/geogebra/add-polygon.js +25 -0
- package/clis/geogebra/eval.js +35 -0
- package/clis/geogebra/geogebra.test.js +175 -0
- package/clis/geogebra/hexagon.js +62 -0
- package/clis/geogebra/info.js +72 -0
- package/clis/geogebra/list.js +35 -0
- package/clis/geogebra/triangle.js +60 -0
- package/clis/geogebra/utils.js +271 -0
- package/clis/jira/attachments.js +28 -0
- package/clis/jira/commands.test.js +287 -0
- package/clis/jira/comments.js +28 -0
- package/clis/jira/issue.js +28 -0
- package/clis/jira/links.js +28 -0
- package/clis/jira/search.js +47 -0
- package/clis/jira/shared.js +256 -0
- package/clis/linkedin/job-detail.js +167 -0
- package/clis/linkedin/job-detail.test.js +38 -0
- package/clis/linkedin/jobs-preferences.js +113 -0
- package/clis/linkedin/jobs-preferences.test.js +43 -0
- package/clis/linkedin/post-analytics.js +74 -0
- package/clis/linkedin/post-analytics.test.js +40 -0
- package/clis/linkedin/posts-core.js +241 -0
- package/clis/linkedin/posts.js +22 -0
- package/clis/linkedin/posts.test.js +40 -0
- package/clis/linkedin/profile-analytics.js +104 -0
- package/clis/linkedin/profile-analytics.test.js +67 -0
- package/clis/linkedin/profile-experience.js +671 -0
- package/clis/linkedin/profile-experience.test.js +152 -0
- package/clis/linkedin/profile-projects.js +311 -0
- package/clis/linkedin/profile-projects.test.js +111 -0
- package/clis/linkedin/profile-read.js +148 -0
- package/clis/linkedin/profile-read.test.js +77 -0
- package/clis/linkedin/services-read.js +213 -0
- package/clis/linkedin/services-read.test.js +105 -0
- package/clis/linkedin/shared.js +124 -0
- package/clis/linkedin/timeline.js +14 -7
- package/clis/notebooklm/add-source.js +269 -0
- package/clis/notebooklm/add-source.test.js +97 -0
- package/clis/notebooklm/create.js +76 -0
- package/clis/notebooklm/create.test.js +58 -0
- package/clis/notebooklm/generate-audio.js +91 -0
- package/clis/notebooklm/generate-audio.test.js +63 -0
- package/clis/notebooklm/generate-slides.js +106 -0
- package/clis/notebooklm/generate-slides.test.js +75 -0
- package/clis/notebooklm/open.test.js +10 -10
- package/clis/notebooklm/rpc.js +20 -6
- package/clis/notebooklm/rpc.test.js +27 -1
- package/clis/notebooklm/utils.js +100 -24
- package/clis/notebooklm/utils.test.js +60 -1
- package/clis/notebooklm/write-note.js +103 -0
- package/clis/notebooklm/write-note.test.js +70 -0
- package/clis/pixiv/detail.js +41 -34
- package/clis/pixiv/detail.test.js +93 -0
- package/clis/pixiv/user.js +36 -31
- package/clis/pixiv/user.test.js +100 -0
- package/clis/pixiv/utils.js +56 -7
- package/clis/suno/generate.js +5 -0
- package/clis/suno/generate.test.js +9 -0
- package/clis/suno/status.js +3 -2
- package/clis/suno/utils.js +33 -24
- package/clis/suno/utils.test.js +106 -0
- package/clis/twitter/followers.js +6 -2
- package/clis/twitter/followers.test.js +19 -1
- package/clis/twitter/following.js +14 -5
- package/clis/twitter/following.test.js +29 -0
- package/clis/twitter/likes.js +12 -4
- package/clis/twitter/likes.test.js +26 -1
- package/clis/twitter/list-add.js +1 -1
- package/clis/twitter/list-remove.js +1 -1
- package/clis/twitter/notifications.js +4 -4
- package/clis/twitter/post.js +62 -4
- package/clis/twitter/post.test.js +35 -3
- package/clis/twitter/profile.js +81 -28
- package/clis/twitter/profile.test.js +113 -2
- package/clis/twitter/quote.js +9 -4
- package/clis/twitter/reply.js +13 -10
- package/clis/twitter/reply.test.js +41 -0
- package/clis/twitter/search.js +1 -1
- package/clis/twitter/search.test.js +35 -0
- package/clis/twitter/shared.js +11 -0
- package/clis/twitter/shared.test.js +37 -1
- package/clis/twitter/utils.js +53 -16
- package/clis/upwork/detail.js +132 -0
- package/clis/upwork/feed.js +109 -0
- package/clis/upwork/search.js +115 -0
- package/clis/upwork/upwork.test.js +566 -0
- package/clis/upwork/utils.js +323 -0
- package/clis/weread/book-search.js +438 -0
- package/clis/weread/book-search.test.js +242 -0
- package/clis/weread/search-regression.test.js +80 -0
- package/clis/weread/search.js +17 -2
- package/clis/xiaohongshu/creator-note-detail.js +165 -28
- package/clis/xiaohongshu/creator-note-detail.test.js +186 -37
- package/clis/xiaohongshu/creator-notes.js +251 -2
- package/clis/xiaohongshu/creator-notes.test.js +79 -2
- package/clis/xiaohongshu/download.js +97 -39
- package/clis/xiaohongshu/download.test.js +201 -0
- package/clis/zhihu/answer-comments.js +2 -21
- package/clis/zhihu/answer-detail.js +2 -31
- package/clis/zhihu/collection.js +2 -14
- package/clis/zhihu/collection.test.js +4 -3
- package/clis/zhihu/question.js +1 -9
- package/clis/zhihu/question.test.js +2 -2
- package/clis/zhihu/search.js +1 -12
- package/clis/zhihu/search.test.js +2 -2
- package/clis/zhihu/text.js +29 -0
- package/clis/zhihu/text.test.js +24 -0
- package/dist/src/browser/network-cache.js +13 -1
- package/dist/src/browser/network-cache.test.js +17 -0
- package/dist/src/download/index.js +13 -1
- package/dist/src/download/index.test.js +23 -1
- package/dist/src/download/media-download.test.js +3 -1
- package/dist/src/download/progress.js +2 -2
- package/dist/src/download/progress.test.js +12 -1
- package/dist/src/output.js +11 -1
- package/dist/src/output.test.js +6 -0
- package/dist/src/registry.js +1 -0
- package/dist/src/registry.test.js +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
2
|
+
import { CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
|
|
3
|
+
import {
|
|
4
|
+
assertLinkedInAuthenticated,
|
|
5
|
+
assertSafeLinkedinUrl,
|
|
6
|
+
normalizeHttpUrl,
|
|
7
|
+
normalizeWhitespace,
|
|
8
|
+
unwrapEvaluateResult,
|
|
9
|
+
} from './shared.js';
|
|
10
|
+
|
|
11
|
+
const DATE_RANGE_RE = /\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+\d{4}\s*[–-]\s*(?:present|[a-z]{3,9}\s+\d{4})\b/i;
|
|
12
|
+
const YEAR_RANGE_RE = /\b\d{4}\s*[–-]\s*(?:present|\d{4})\b/i;
|
|
13
|
+
|
|
14
|
+
function normalizeProfileUrl(value) {
|
|
15
|
+
const url = assertSafeLinkedinUrl(value || 'https://www.linkedin.com/in/me/', 'profile-url', '/in/me/');
|
|
16
|
+
const parsed = new URL(url);
|
|
17
|
+
if (!/^\/in\/[^/?#]+\/?$/.test(parsed.pathname)) {
|
|
18
|
+
throw new CommandExecutionError('LinkedIn profile-experience requires a /in/<handle>/ profile URL');
|
|
19
|
+
}
|
|
20
|
+
return parsed.toString();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function profileExperienceUrl(profileUrl) {
|
|
24
|
+
const url = assertSafeLinkedinUrl(profileUrl, 'profile-url');
|
|
25
|
+
const parsed = new URL(url);
|
|
26
|
+
if (!/^\/in\/[^/?#]+\/?$/.test(parsed.pathname) || parsed.pathname === '/in/me/') {
|
|
27
|
+
throw new CommandExecutionError('LinkedIn profile-experience requires a resolved /in/<handle>/ profile URL');
|
|
28
|
+
}
|
|
29
|
+
return new URL(`${parsed.pathname.replace(/\/?$/, '/') }details/experience/`, 'https://www.linkedin.com').toString();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function decodeLinkedInSafetyUrl(value) {
|
|
33
|
+
const url = normalizeWhitespace(value);
|
|
34
|
+
if (!url) return '';
|
|
35
|
+
try {
|
|
36
|
+
const parsed = new URL(url);
|
|
37
|
+
if (parsed.hostname.endsWith('linkedin.com') && parsed.pathname === '/safety/go/') {
|
|
38
|
+
return normalizeHttpUrl(parsed.searchParams.get('url') || '');
|
|
39
|
+
}
|
|
40
|
+
} catch {}
|
|
41
|
+
return normalizeHttpUrl(url);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isChromeLine(line) {
|
|
45
|
+
return /^(show all|show less|edit|delete|add experience|back to profile|experience|show credential|show media|see more|see less|←|\+)$/i.test(line);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isDateLine(line) {
|
|
49
|
+
return DATE_RANGE_RE.test(line) || YEAR_RANGE_RE.test(line);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function splitLinkedInDotLine(line) {
|
|
53
|
+
return normalizeWhitespace(line).split(/\s*[·•]\s*/).map(normalizeWhitespace).filter(Boolean);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parseDateRangeParts(dateLine) {
|
|
57
|
+
const primary = splitLinkedInDotLine(dateLine)[0] || normalizeWhitespace(dateLine);
|
|
58
|
+
const match = primary.match(DATE_RANGE_RE) || primary.match(YEAR_RANGE_RE);
|
|
59
|
+
const dateRange = match ? normalizeWhitespace(match[0]) : primary;
|
|
60
|
+
const [startDate = '', endDate = ''] = dateRange.split(/\s*[–-]\s*/).map(normalizeWhitespace);
|
|
61
|
+
return { dateRange, startDate, endDate };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function parseCompanyLine(companyLine) {
|
|
65
|
+
const parts = splitLinkedInDotLine(companyLine);
|
|
66
|
+
return {
|
|
67
|
+
company: parts[0] || normalizeWhitespace(companyLine),
|
|
68
|
+
employment_type: parts.slice(1).join(' · '),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function parseLocationLine(locationLine) {
|
|
73
|
+
const parts = splitLinkedInDotLine(locationLine);
|
|
74
|
+
return {
|
|
75
|
+
location: parts[0] || normalizeWhitespace(locationLine),
|
|
76
|
+
location_type: parts.slice(1).join(' · '),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function parseExperienceText(rawText, profileUrl, index, totalCount = 0) {
|
|
81
|
+
const lines = String(rawText || '')
|
|
82
|
+
.split(/\n+/)
|
|
83
|
+
.map(normalizeWhitespace)
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
.filter((line) => !isChromeLine(line));
|
|
86
|
+
const title = lines[0] || '';
|
|
87
|
+
const dateIndex = lines.findIndex(isDateLine);
|
|
88
|
+
const companyLine = dateIndex > 1 ? lines[1] : (lines[1] || '');
|
|
89
|
+
const { company, employment_type: parsedEmploymentType } = parseCompanyLine(companyLine);
|
|
90
|
+
const dateParts = dateIndex >= 0 ? parseDateRangeParts(lines[dateIndex]) : { dateRange: '', startDate: '', endDate: '' };
|
|
91
|
+
const locationLine = dateIndex >= 0 && lines[dateIndex + 1] && !/^skills?:/i.test(lines[dateIndex + 1])
|
|
92
|
+
? lines[dateIndex + 1]
|
|
93
|
+
: '';
|
|
94
|
+
const { location, location_type: parsedLocationType } = parseLocationLine(locationLine);
|
|
95
|
+
const skillLine = lines.find((line) => /\bskills?:/i.test(line)) || '';
|
|
96
|
+
const description = lines
|
|
97
|
+
.filter((line, lineIndex) => lineIndex !== 0)
|
|
98
|
+
.filter((line) => line !== companyLine && line !== lines[dateIndex] && line !== locationLine && line !== skillLine)
|
|
99
|
+
.join(' ');
|
|
100
|
+
return {
|
|
101
|
+
rank: index + 1,
|
|
102
|
+
total_count: totalCount,
|
|
103
|
+
title,
|
|
104
|
+
employment_type: parsedEmploymentType,
|
|
105
|
+
company,
|
|
106
|
+
date_range: dateParts.dateRange,
|
|
107
|
+
start_date: dateParts.startDate,
|
|
108
|
+
end_date: dateParts.endDate,
|
|
109
|
+
location,
|
|
110
|
+
location_type: parsedLocationType,
|
|
111
|
+
description,
|
|
112
|
+
skills: skillLine.replace(/^skills?:\s*/i, ''),
|
|
113
|
+
media: '',
|
|
114
|
+
urls: '',
|
|
115
|
+
profile_url: profileUrl,
|
|
116
|
+
raw_text: lines.join(' | '),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function parseExperienceSectionText(rawText, profileUrl) {
|
|
121
|
+
const stopLine = (line) => /^(who your viewers also viewed|people you may know|about|accessibility|talent solutions|community guidelines|careers|marketing solutions|privacy & terms)$/i.test(line);
|
|
122
|
+
const lines = String(rawText || '')
|
|
123
|
+
.split(/\n+/)
|
|
124
|
+
.map(normalizeWhitespace)
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.filter((line) => !isChromeLine(line));
|
|
127
|
+
const scoped = [];
|
|
128
|
+
for (const line of lines) {
|
|
129
|
+
if (stopLine(line)) break;
|
|
130
|
+
scoped.push(line);
|
|
131
|
+
}
|
|
132
|
+
const rows = [];
|
|
133
|
+
for (let i = 0; i < scoped.length - 2; i++) {
|
|
134
|
+
if (!isDateLine(scoped[i + 2]) && !isDateLine(scoped[i + 1])) continue;
|
|
135
|
+
const dateOffset = isDateLine(scoped[i + 1]) ? 1 : 2;
|
|
136
|
+
let end = scoped.length;
|
|
137
|
+
for (let j = i + dateOffset + 1; j < scoped.length - 2; j++) {
|
|
138
|
+
if (isDateLine(scoped[j + 2]) || isDateLine(scoped[j + 1])) {
|
|
139
|
+
end = j;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const row = parseExperienceText(scoped.slice(i, end).join('\n'), profileUrl, rows.length);
|
|
144
|
+
if (row.title && row.company) rows.push(row);
|
|
145
|
+
i = end - 1;
|
|
146
|
+
}
|
|
147
|
+
return rows.map((row) => ({ ...row, total_count: rows.length }));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function buildExperienceExtractionScript() {
|
|
151
|
+
return String.raw`(() => {
|
|
152
|
+
const clean = (s) => String(s || '').replace(/[\u00a0\u202f]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
153
|
+
const DATE_RANGE_RE = /\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+\d{4}\s*[–-]\s*(?:present|[a-z]{3,9}\s+\d{4})\b/i;
|
|
154
|
+
const YEAR_RANGE_RE = /\b\d{4}\s*[–-]\s*(?:present|\d{4})\b/i;
|
|
155
|
+
const isDateLine = (line) => DATE_RANGE_RE.test(line) || YEAR_RANGE_RE.test(line);
|
|
156
|
+
const isChromeLine = (line) => /^(show all|show less|edit|delete|add experience|back to profile|experience|show credential|show media|see more|see less|←|\+)$/i.test(line);
|
|
157
|
+
const splitLines = (text) => String(text || '').split(/\n+/).map(clean).filter(Boolean);
|
|
158
|
+
const splitDotLine = (line) => clean(line).split(/\s*[·•]\s*/).map(clean).filter(Boolean);
|
|
159
|
+
const looksLocationLine = (line) => /remote|hybrid|on-site|india|area|bengaluru|jaipur|delhi|mumbai|pune|gurugram|noida|hyderabad|chennai|kolkata/i.test(line || '');
|
|
160
|
+
const decodeLinkedInSafetyUrl = (value) => {
|
|
161
|
+
if (!value) return '';
|
|
162
|
+
try {
|
|
163
|
+
const parsed = new URL(value, location.origin);
|
|
164
|
+
if (parsed.hostname.endsWith('linkedin.com') && parsed.pathname === '/safety/go/') {
|
|
165
|
+
const decoded = parsed.searchParams.get('url') || '';
|
|
166
|
+
try {
|
|
167
|
+
const target = new URL(decoded, location.origin);
|
|
168
|
+
if (target.protocol === 'http:' || target.protocol === 'https:') return target.toString();
|
|
169
|
+
return '';
|
|
170
|
+
} catch {
|
|
171
|
+
return '';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') return parsed.toString();
|
|
175
|
+
return '';
|
|
176
|
+
} catch {
|
|
177
|
+
return '';
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const parseDateParts = (dateLine) => {
|
|
181
|
+
const primary = splitDotLine(dateLine)[0] || clean(dateLine);
|
|
182
|
+
const match = primary.match(DATE_RANGE_RE) || primary.match(YEAR_RANGE_RE);
|
|
183
|
+
const dateRange = match ? clean(match[0]) : primary;
|
|
184
|
+
const parts = dateRange.split(/\s*[–-]\s*/).map(clean);
|
|
185
|
+
return { dateRange, startDate: parts[0] || '', endDate: parts[1] || '' };
|
|
186
|
+
};
|
|
187
|
+
const parseRow = (root, index, totalCount, context = {}) => {
|
|
188
|
+
const raw = clean(root.innerText || root.textContent || '');
|
|
189
|
+
const lines = splitLines(root.innerText || root.textContent || '').filter((line) => !isChromeLine(line));
|
|
190
|
+
const ariaMatch = clean(context.ariaLabel || '').match(/^edit\s+(.+?)\s+at\s+(.+)$/i);
|
|
191
|
+
const title = lines[0] || ariaMatch?.[1] || '';
|
|
192
|
+
const dateIndex = lines.findIndex(isDateLine);
|
|
193
|
+
const companyLine = dateIndex > 1 ? lines[1] : (lines[1] || '');
|
|
194
|
+
const companyParts = splitDotLine(companyLine);
|
|
195
|
+
const groupEmploymentParts = splitDotLine(context.employment_type || '');
|
|
196
|
+
const company = (dateIndex > 1 ? companyParts[0] : '') || context.company || ariaMatch?.[2] || companyParts[0] || companyLine;
|
|
197
|
+
const parsedEmploymentType = dateIndex > 1
|
|
198
|
+
? companyParts.slice(1).join(' · ')
|
|
199
|
+
: (groupEmploymentParts[0] || context.employment_type || '');
|
|
200
|
+
const dateParts = dateIndex >= 0 ? parseDateParts(lines[dateIndex]) : { dateRange: '', startDate: '', endDate: '' };
|
|
201
|
+
const lineAfterDate = dateIndex >= 0 ? lines[dateIndex + 1] : '';
|
|
202
|
+
const locationLine = lineAfterDate && looksLocationLine(lineAfterDate) && !/^skills?:/i.test(lineAfterDate)
|
|
203
|
+
? lines[dateIndex + 1]
|
|
204
|
+
: (context.location || '');
|
|
205
|
+
const locationParts = splitDotLine(locationLine || context.location || '');
|
|
206
|
+
const skillLine = lines.find((line) => /\bskills?:|(?:\+[\d,]+\s+skills?\b)|(?:\band\s+\+[\d,]+\s+skills?\b)/i.test(line)) || '';
|
|
207
|
+
const skillUrl = Array.from(root.querySelectorAll('a[href*="/skill-associations-details/"]'))
|
|
208
|
+
.map((link) => new URL(link.href, location.origin).toString())
|
|
209
|
+
.find(Boolean) || '';
|
|
210
|
+
const media = Array.from(root.querySelectorAll('img[alt], video'))
|
|
211
|
+
.map((node) => node.tagName.toLowerCase() === 'video' ? 'video' : clean(node.getAttribute('alt') || ''))
|
|
212
|
+
.filter(Boolean)
|
|
213
|
+
.filter((value) => !/profile|photo of|emoji|reaction|company logo|\blogo$/i.test(value));
|
|
214
|
+
const mediaTitleLines = Array.from(root.querySelectorAll('a[href*="/overlay/Position/"] p, a[href*="/treasury/"] p'))
|
|
215
|
+
.map((node) => clean(node.textContent || ''))
|
|
216
|
+
.filter(Boolean);
|
|
217
|
+
const mediaBodyLines = Array.from(root.querySelectorAll('a[href*="/overlay/Position/"] span, a[href*="/treasury/"] span'))
|
|
218
|
+
.map((node) => clean(node.textContent || ''))
|
|
219
|
+
.filter(Boolean);
|
|
220
|
+
const firstMediaLineIndex = lines.findIndex((line) => mediaTitleLines.includes(line));
|
|
221
|
+
const description = lines
|
|
222
|
+
.filter((line, lineIndex) => lineIndex !== 0)
|
|
223
|
+
.filter((line, lineIndex) => firstMediaLineIndex < 0 || lineIndex < firstMediaLineIndex)
|
|
224
|
+
.filter((line) => line !== companyLine && line !== lines[dateIndex] && line !== locationLine && line !== skillLine)
|
|
225
|
+
.filter((line) => !mediaTitleLines.includes(line))
|
|
226
|
+
.filter((line) => !mediaBodyLines.includes(line))
|
|
227
|
+
.filter((line) => !/^thumbnail for\b/i.test(line))
|
|
228
|
+
.join(' ');
|
|
229
|
+
const urls = Array.from(root.querySelectorAll('a[href]'))
|
|
230
|
+
.map((link) => new URL(link.href, location.origin).toString())
|
|
231
|
+
.filter((href) => {
|
|
232
|
+
try {
|
|
233
|
+
const parsed = new URL(href);
|
|
234
|
+
const path = parsed.pathname;
|
|
235
|
+
if (/\/details\/experience\/edit\/forms\//i.test(path)) return false;
|
|
236
|
+
if (/\/skill-associations-details\//i.test(path)) return false;
|
|
237
|
+
if (/\/overlay\/Position\/|\/treasury\//i.test(path)) return true;
|
|
238
|
+
if (/\/in\//i.test(path) || /\/search\//i.test(path) || /\/company\//i.test(path)) return false;
|
|
239
|
+
return true;
|
|
240
|
+
} catch {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
.map(decodeLinkedInSafetyUrl)
|
|
245
|
+
.map((href) => /linkedin\.com/i.test(href) ? href.replace(/[?#].*$/, '') : href);
|
|
246
|
+
return {
|
|
247
|
+
rank: index + 1,
|
|
248
|
+
total_count: totalCount,
|
|
249
|
+
title,
|
|
250
|
+
employment_type: parsedEmploymentType,
|
|
251
|
+
company,
|
|
252
|
+
date_range: dateParts.dateRange,
|
|
253
|
+
start_date: dateParts.startDate,
|
|
254
|
+
end_date: dateParts.endDate,
|
|
255
|
+
location: locationParts[0] || locationLine,
|
|
256
|
+
location_type: locationParts.slice(1).join(' · '),
|
|
257
|
+
description,
|
|
258
|
+
skills: skillLine.replace(/^skills?:\s*/i, ''),
|
|
259
|
+
media: Array.from(new Set(media)).join(' | '),
|
|
260
|
+
urls: Array.from(new Set(urls)).join(' | '),
|
|
261
|
+
skill_url: skillUrl,
|
|
262
|
+
media_url: urls.find((href) => /\/overlay\/Position\/|\/treasury\//i.test(href)) || '',
|
|
263
|
+
profile_url: location.href.replace(/\/details\/experience\/?.*$/i, '/'),
|
|
264
|
+
raw_text: raw,
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
const main = document.querySelector('main') || document.body;
|
|
268
|
+
const findSmallestExperienceRoot = (link) => {
|
|
269
|
+
const ownFormPath = new URL(link.href, location.origin).pathname;
|
|
270
|
+
let node = link.parentElement;
|
|
271
|
+
let best = link;
|
|
272
|
+
while (node && node !== main && node !== document.body) {
|
|
273
|
+
const text = clean(node.innerText || node.textContent || '');
|
|
274
|
+
const uniqueFormPaths = Array.from(new Set(Array.from(node.querySelectorAll('a[href*="/details/experience/edit/forms/"]'))
|
|
275
|
+
.map((formLink) => new URL(formLink.href, location.origin).pathname)));
|
|
276
|
+
if (uniqueFormPaths.length > 1) break;
|
|
277
|
+
if (uniqueFormPaths.includes(ownFormPath) && isDateLine(text) && text.length < 2500) best = node;
|
|
278
|
+
node = node.parentElement;
|
|
279
|
+
}
|
|
280
|
+
return best || link;
|
|
281
|
+
};
|
|
282
|
+
const findGroupContext = (root) => {
|
|
283
|
+
let group = root.parentElement;
|
|
284
|
+
while (group && group !== main && group !== document.body && !group.querySelector('ul')) {
|
|
285
|
+
group = group.parentElement;
|
|
286
|
+
}
|
|
287
|
+
if (!group || group === main || group === document.body) return {};
|
|
288
|
+
const listText = clean(root.innerText || root.textContent || '');
|
|
289
|
+
const groupLines = splitLines(group.innerText || group.textContent || '')
|
|
290
|
+
.filter((line) => !isChromeLine(line));
|
|
291
|
+
const companyLink = Array.from(group.querySelectorAll('a[href*="/company/"] p'))
|
|
292
|
+
.map((node) => clean(node.textContent || ''))
|
|
293
|
+
.find(Boolean);
|
|
294
|
+
const groupCompany = companyLink || groupLines.find((line) => !isDateLine(line) && !listText.includes(line) && !/full-time|part-time|contract|freelance|self-employed/i.test(line)) || '';
|
|
295
|
+
const groupEmployment = groupLines.find((line) => /full-time|part-time|contract|freelance|self-employed|internship/i.test(line)) || '';
|
|
296
|
+
const groupLocation = groupLines.find((line) => /remote|hybrid|on-site|india|area|bengaluru|jaipur/i.test(line) && !isDateLine(line) && line !== groupEmployment && !listText.includes(line)) || '';
|
|
297
|
+
return {
|
|
298
|
+
company: groupCompany,
|
|
299
|
+
employment_type: groupEmployment,
|
|
300
|
+
location: groupLocation,
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
const formLinks = Array.from(main.querySelectorAll('a[href*="/details/experience/edit/forms/"]'));
|
|
304
|
+
const linksByForm = new Map();
|
|
305
|
+
for (const link of formLinks) {
|
|
306
|
+
const href = new URL(link.href, location.origin).pathname;
|
|
307
|
+
const current = linksByForm.get(href) || {};
|
|
308
|
+
const ariaLabel = clean(link.getAttribute('aria-label') || current.ariaLabel || '');
|
|
309
|
+
const text = clean(link.innerText || link.textContent || current.text || '');
|
|
310
|
+
linksByForm.set(href, { link: current.link || link, ariaLabel, text });
|
|
311
|
+
}
|
|
312
|
+
const candidates = Array.from(linksByForm.values())
|
|
313
|
+
.map(({ link, ariaLabel }) => {
|
|
314
|
+
const root = findSmallestExperienceRoot(link);
|
|
315
|
+
return { root, ariaLabel, context: findGroupContext(root) };
|
|
316
|
+
})
|
|
317
|
+
.filter(({ root }) => {
|
|
318
|
+
const text = clean(root.innerText || root.textContent || '');
|
|
319
|
+
if (text.length < 12) return false;
|
|
320
|
+
if (/^(experience|show all|show less|edit|add experience)$/i.test(text)) return false;
|
|
321
|
+
return isDateLine(text) && !/\bfeatured\b/i.test(text);
|
|
322
|
+
});
|
|
323
|
+
const experienceRows = [];
|
|
324
|
+
const seen = new Set();
|
|
325
|
+
for (const candidate of candidates) {
|
|
326
|
+
const row = parseRow(candidate.root, experienceRows.length, 0, { ...candidate.context, ariaLabel: candidate.ariaLabel });
|
|
327
|
+
const key = row.title + '::' + row.company + '::' + row.date_range + '::' + row.description.slice(0, 80);
|
|
328
|
+
if (!row.title || !row.company || seen.has(key)) continue;
|
|
329
|
+
seen.add(key);
|
|
330
|
+
experienceRows.push(row);
|
|
331
|
+
}
|
|
332
|
+
if (experienceRows.length === 0) {
|
|
333
|
+
const section = Array.from(main.querySelectorAll('section'))
|
|
334
|
+
.find((node) => /^Experience\b/i.test(clean(node.innerText || node.textContent || '')));
|
|
335
|
+
const sectionLines = splitLines(section?.innerText || section?.textContent || '').filter((line) => !isChromeLine(line));
|
|
336
|
+
const scopedLines = [];
|
|
337
|
+
for (const line of sectionLines) {
|
|
338
|
+
if (/^(who your viewers also viewed|people you may know|about|accessibility|talent solutions|community guidelines|careers|marketing solutions|privacy & terms)$/i.test(line)) break;
|
|
339
|
+
scopedLines.push(line);
|
|
340
|
+
}
|
|
341
|
+
for (let i = 0; i < scopedLines.length - 2; i++) {
|
|
342
|
+
if (!isDateLine(scopedLines[i + 2]) && !isDateLine(scopedLines[i + 1])) continue;
|
|
343
|
+
const dateOffset = isDateLine(scopedLines[i + 1]) ? 1 : 2;
|
|
344
|
+
let end = scopedLines.length;
|
|
345
|
+
for (let j = i + dateOffset + 1; j < scopedLines.length - 2; j++) {
|
|
346
|
+
if (isDateLine(scopedLines[j + 2]) || isDateLine(scopedLines[j + 1])) {
|
|
347
|
+
end = j;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const syntheticRoot = {
|
|
352
|
+
innerText: scopedLines.slice(i, end).join('\n'),
|
|
353
|
+
textContent: scopedLines.slice(i, end).join('\n'),
|
|
354
|
+
querySelectorAll: () => [],
|
|
355
|
+
};
|
|
356
|
+
const row = parseRow(syntheticRoot, experienceRows.length, 0);
|
|
357
|
+
const key = row.title + '::' + row.company + '::' + row.date_range + '::' + row.description.slice(0, 80);
|
|
358
|
+
if (row.title && row.company && !seen.has(key)) {
|
|
359
|
+
seen.add(key);
|
|
360
|
+
experienceRows.push(row);
|
|
361
|
+
}
|
|
362
|
+
i = end - 1;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
experienceRows: experienceRows.map((row, index) => ({ ...row, rank: index + 1, total_count: experienceRows.length })),
|
|
367
|
+
pageHref: location.href,
|
|
368
|
+
pageTitle: document.title || '',
|
|
369
|
+
};
|
|
370
|
+
})()`;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function normalizeExperience(row) {
|
|
374
|
+
if (!row || typeof row !== 'object') {
|
|
375
|
+
throw new CommandExecutionError('LinkedIn profile-experience returned malformed row');
|
|
376
|
+
}
|
|
377
|
+
const title = normalizeWhitespace(row.title);
|
|
378
|
+
if (!title) throw new CommandExecutionError('LinkedIn profile-experience returned an experience without a title');
|
|
379
|
+
return {
|
|
380
|
+
rank: Number(row.rank) || 0,
|
|
381
|
+
total_count: Number(row.total_count) || 0,
|
|
382
|
+
title,
|
|
383
|
+
employment_type: normalizeWhitespace(row.employment_type),
|
|
384
|
+
company: normalizeWhitespace(row.company),
|
|
385
|
+
date_range: normalizeWhitespace(row.date_range),
|
|
386
|
+
start_date: normalizeWhitespace(row.start_date),
|
|
387
|
+
end_date: normalizeWhitespace(row.end_date),
|
|
388
|
+
location: normalizeWhitespace(row.location),
|
|
389
|
+
location_type: normalizeWhitespace(row.location_type),
|
|
390
|
+
description: normalizeWhitespace(row.description),
|
|
391
|
+
skills: normalizeWhitespace(row.skills),
|
|
392
|
+
media: normalizeWhitespace(row.media),
|
|
393
|
+
urls: normalizeWhitespace(row.urls),
|
|
394
|
+
skill_url: normalizeWhitespace(row.skill_url),
|
|
395
|
+
media_url: normalizeWhitespace(row.media_url),
|
|
396
|
+
profile_url: normalizeWhitespace(row.profile_url),
|
|
397
|
+
raw_text: normalizeWhitespace(row.raw_text),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function buildDialogExtractionScript() {
|
|
402
|
+
return String.raw`(() => {
|
|
403
|
+
const clean = (s) => String(s || '').replace(/[\u00a0\u202f]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
404
|
+
const decodeLinkedInSafetyUrl = (value) => {
|
|
405
|
+
if (!value) return '';
|
|
406
|
+
try {
|
|
407
|
+
const parsed = new URL(value, location.origin);
|
|
408
|
+
if (parsed.hostname.endsWith('linkedin.com') && parsed.pathname === '/safety/go/') {
|
|
409
|
+
const decoded = parsed.searchParams.get('url') || '';
|
|
410
|
+
try {
|
|
411
|
+
const target = new URL(decoded, location.origin);
|
|
412
|
+
if (target.protocol === 'http:' || target.protocol === 'https:') return target.toString();
|
|
413
|
+
return '';
|
|
414
|
+
} catch {
|
|
415
|
+
return '';
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') return parsed.toString();
|
|
419
|
+
return '';
|
|
420
|
+
} catch {
|
|
421
|
+
return '';
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const dialog = document.querySelector('dialog[open], dialog[data-testid="dialog"]') || document.querySelector('[role="dialog"]');
|
|
425
|
+
if (!dialog) return { title: '', skills: [], media: [], urls: [] };
|
|
426
|
+
const title = clean(dialog.querySelector('h1,h2,h3,[id="dialog-header"]')?.textContent || '');
|
|
427
|
+
const text = clean(dialog.innerText || dialog.textContent || '');
|
|
428
|
+
const skills = Array.from(dialog.querySelectorAll('a[href*="PROFILE_PAGE_SKILL_NAVIGATION"] p, a[href*="PROFILE_PAGE_SKILL_NAVIGATION"] span, button[aria-label^="Expand "]'))
|
|
429
|
+
.map((node) => {
|
|
430
|
+
const aria = clean(node.getAttribute?.('aria-label') || '');
|
|
431
|
+
if (/^expand\s+/i.test(aria)) return aria.replace(/^expand\s+/i, '');
|
|
432
|
+
return clean(node.textContent || '');
|
|
433
|
+
})
|
|
434
|
+
.filter(Boolean)
|
|
435
|
+
.filter((value) => !/^learn more about/i.test(value));
|
|
436
|
+
const media = Array.from(dialog.querySelectorAll('a[href], [role="link"], li, article'))
|
|
437
|
+
.map((node) => {
|
|
438
|
+
const nodeText = clean(node.innerText || node.textContent || '');
|
|
439
|
+
if (!nodeText || nodeText.length > 800) return null;
|
|
440
|
+
const href = node.matches?.('a[href]') ? decodeLinkedInSafetyUrl(node.href) : '';
|
|
441
|
+
const image = node.querySelector?.('img[alt]')?.getAttribute('alt') || '';
|
|
442
|
+
return { label: nodeText, url: href, image: clean(image) };
|
|
443
|
+
})
|
|
444
|
+
.filter(Boolean);
|
|
445
|
+
const urls = Array.from(dialog.querySelectorAll('a[href]'))
|
|
446
|
+
.map((link) => decodeLinkedInSafetyUrl(link.href))
|
|
447
|
+
.filter(Boolean)
|
|
448
|
+
.filter((href) => !/linkedin\.com\/search\/results\/all/i.test(href));
|
|
449
|
+
const mediaViewUrl = urls.find((href) => !/linkedin\.com/i.test(href)) || '';
|
|
450
|
+
const mediaImage = dialog.querySelector('img[src]')?.getAttribute('src') || '';
|
|
451
|
+
const mediaLines = String(dialog.innerText || dialog.textContent || '')
|
|
452
|
+
.split(/\n+/)
|
|
453
|
+
.map(clean)
|
|
454
|
+
.filter(Boolean)
|
|
455
|
+
.filter((line) => !/^(media|view|previous|next)$/i.test(line));
|
|
456
|
+
const primaryMedia = /^media$/i.test(title) && mediaLines.length
|
|
457
|
+
? [{ label: mediaLines.join(' - '), url: mediaViewUrl, image: mediaImage }]
|
|
458
|
+
: media;
|
|
459
|
+
return {
|
|
460
|
+
title,
|
|
461
|
+
skills: Array.from(new Set(skills)),
|
|
462
|
+
media: primaryMedia,
|
|
463
|
+
urls: Array.from(new Set(urls)),
|
|
464
|
+
};
|
|
465
|
+
})()`;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
async function clickOverlayAndExtract(page, url, nth = undefined) {
|
|
469
|
+
const normalizedUrl = normalizeWhitespace(url);
|
|
470
|
+
if (!normalizedUrl) return null;
|
|
471
|
+
const overlayId = normalizedUrl.match(/\/overlay\/(?:Position\/)?(\d+)\//i)?.[1] || '';
|
|
472
|
+
if (!overlayId) return null;
|
|
473
|
+
const isSkillOverlay = /skill-associations-details/i.test(normalizedUrl);
|
|
474
|
+
const selector = isSkillOverlay
|
|
475
|
+
? `a[href*="/overlay/${overlayId}/skill-associations-details/"]`
|
|
476
|
+
: `a[href*="/overlay/Position/${overlayId}/treasury/"], a[href*="/treasury/"][href*="${overlayId}"]`;
|
|
477
|
+
const closeDialog = async () => {
|
|
478
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
479
|
+
const hasDialog = unwrapEvaluateResult(await page.evaluate('Boolean(document.querySelector("dialog[data-testid=\\"dialog\\"], [role=\\"dialog\\"]"))'));
|
|
480
|
+
if (!hasDialog) return;
|
|
481
|
+
try {
|
|
482
|
+
await page.click('dialog button[aria-label="Dismiss"], [role="dialog"] button[aria-label="Dismiss"]');
|
|
483
|
+
} catch {
|
|
484
|
+
await page.evaluate('document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }))');
|
|
485
|
+
}
|
|
486
|
+
await page.wait(1);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
await closeDialog();
|
|
490
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
491
|
+
try {
|
|
492
|
+
await page.click(selector, isSkillOverlay
|
|
493
|
+
? {}
|
|
494
|
+
: { nth: 0 });
|
|
495
|
+
} catch {
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
await page.wait({ selector: 'dialog[data-testid="dialog"], [role="dialog"]', timeout: 10000 });
|
|
500
|
+
} catch {}
|
|
501
|
+
if (isSkillOverlay) {
|
|
502
|
+
try {
|
|
503
|
+
await page.wait({ selector: 'dialog button[aria-label^="Expand "], [role="dialog"] button[aria-label^="Expand "]', timeout: 10000 });
|
|
504
|
+
} catch {}
|
|
505
|
+
} else {
|
|
506
|
+
await page.wait(2);
|
|
507
|
+
for (let index = 0; index < Number(nth || 0); index += 1) {
|
|
508
|
+
await page.evaluate(String.raw`(() => {
|
|
509
|
+
const dialog = document.querySelector('dialog[data-testid="dialog"], [role="dialog"]');
|
|
510
|
+
const button = Array.from(dialog?.querySelectorAll('button') || [])
|
|
511
|
+
.find((candidate) => /^\s*next\s*$/i.test(candidate.innerText || candidate.textContent || ''));
|
|
512
|
+
if (button) button.click();
|
|
513
|
+
return Boolean(button);
|
|
514
|
+
})()`);
|
|
515
|
+
await page.wait(1);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
let payload = unwrapEvaluateResult(await page.evaluate(buildDialogExtractionScript()));
|
|
519
|
+
if (isSkillOverlay && (!payload?.skills || payload.skills.length === 0)) {
|
|
520
|
+
await page.wait(3);
|
|
521
|
+
payload = unwrapEvaluateResult(await page.evaluate(buildDialogExtractionScript()));
|
|
522
|
+
}
|
|
523
|
+
await closeDialog();
|
|
524
|
+
if (payload && typeof payload === 'object') {
|
|
525
|
+
if (!isSkillOverlay || payload.skills?.length) return payload;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function serializeMediaDetails(details) {
|
|
532
|
+
if (!details || !Array.isArray(details.media)) return '';
|
|
533
|
+
const rows = details.media
|
|
534
|
+
.map((item) => {
|
|
535
|
+
const text = normalizeWhitespace(item?.label);
|
|
536
|
+
const url = normalizeWhitespace(item?.url);
|
|
537
|
+
if (!text && !url) return '';
|
|
538
|
+
return url ? `${text} <${url}>` : text;
|
|
539
|
+
})
|
|
540
|
+
.filter(Boolean);
|
|
541
|
+
return Array.from(new Set(rows)).join(' | ');
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function splitPipeValues(value) {
|
|
545
|
+
return normalizeWhitespace(value).split('|').map(normalizeWhitespace).filter(Boolean);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
async function enrichExperienceRows(page, rows) {
|
|
549
|
+
const enriched = [];
|
|
550
|
+
for (const row of rows) {
|
|
551
|
+
let nextRow = { ...row };
|
|
552
|
+
const skillDetails = await clickOverlayAndExtract(page, nextRow.skill_url);
|
|
553
|
+
if (skillDetails?.skills?.length) {
|
|
554
|
+
nextRow.skills = skillDetails.skills.join(', ');
|
|
555
|
+
}
|
|
556
|
+
const mediaCount = splitPipeValues(nextRow.media).length;
|
|
557
|
+
const mediaDetailRows = [];
|
|
558
|
+
const mediaUrls = [];
|
|
559
|
+
for (let mediaIndex = 0; mediaIndex < mediaCount; mediaIndex += 1) {
|
|
560
|
+
const mediaDetails = await clickOverlayAndExtract(page, nextRow.media_url, mediaIndex);
|
|
561
|
+
if (!mediaDetails) continue;
|
|
562
|
+
const mediaText = serializeMediaDetails(mediaDetails);
|
|
563
|
+
if (mediaText) nextRow.media = mediaText;
|
|
564
|
+
if (Array.isArray(mediaDetails.urls) && mediaDetails.urls.length) {
|
|
565
|
+
mediaUrls.push(...mediaDetails.urls.map(normalizeWhitespace).filter(Boolean));
|
|
566
|
+
}
|
|
567
|
+
if (mediaText) mediaDetailRows.push(mediaText);
|
|
568
|
+
}
|
|
569
|
+
if (mediaDetailRows.length) {
|
|
570
|
+
nextRow.media = Array.from(new Set(mediaDetailRows)).join(' | ');
|
|
571
|
+
}
|
|
572
|
+
if (mediaUrls.length) {
|
|
573
|
+
const combinedUrls = [
|
|
574
|
+
...splitPipeValues(nextRow.urls),
|
|
575
|
+
...mediaUrls,
|
|
576
|
+
];
|
|
577
|
+
nextRow.urls = Array.from(new Set(combinedUrls)).join(' | ');
|
|
578
|
+
nextRow.media_url = Array.from(new Set(mediaUrls.filter((href) => !/linkedin\.com/i.test(href)))).join(' | ') || nextRow.media_url;
|
|
579
|
+
}
|
|
580
|
+
enriched.push(nextRow);
|
|
581
|
+
}
|
|
582
|
+
return enriched;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
cli({
|
|
586
|
+
site: 'linkedin',
|
|
587
|
+
name: 'profile-experience',
|
|
588
|
+
access: 'read',
|
|
589
|
+
description: 'Read visible LinkedIn profile experience entries with titles, dates, locations, skills, media, and URLs',
|
|
590
|
+
domain: 'www.linkedin.com',
|
|
591
|
+
strategy: Strategy.COOKIE,
|
|
592
|
+
browser: true,
|
|
593
|
+
args: [
|
|
594
|
+
{ name: 'profile-url', type: 'string', required: false, help: 'LinkedIn /in/<handle>/ profile URL. Defaults to /in/me/.' },
|
|
595
|
+
],
|
|
596
|
+
columns: [
|
|
597
|
+
'rank',
|
|
598
|
+
'total_count',
|
|
599
|
+
'title',
|
|
600
|
+
'employment_type',
|
|
601
|
+
'company',
|
|
602
|
+
'date_range',
|
|
603
|
+
'start_date',
|
|
604
|
+
'end_date',
|
|
605
|
+
'location',
|
|
606
|
+
'location_type',
|
|
607
|
+
'description',
|
|
608
|
+
'skills',
|
|
609
|
+
'media',
|
|
610
|
+
'urls',
|
|
611
|
+
'skill_url',
|
|
612
|
+
'media_url',
|
|
613
|
+
'profile_url',
|
|
614
|
+
'raw_text',
|
|
615
|
+
],
|
|
616
|
+
func: async (page, args) => {
|
|
617
|
+
if (!page) throw new CommandExecutionError('Browser session required for linkedin profile-experience');
|
|
618
|
+
const profileUrl = normalizeProfileUrl(args['profile-url']);
|
|
619
|
+
let experienceUrl;
|
|
620
|
+
if (!args['profile-url'] || new URL(profileUrl).pathname === '/in/me/') {
|
|
621
|
+
await page.goto(profileUrl);
|
|
622
|
+
await page.wait(4);
|
|
623
|
+
await assertLinkedInAuthenticated(page, 'LinkedIn profile-experience');
|
|
624
|
+
const resolvedProfileUrl = unwrapEvaluateResult(await page.evaluate(String.raw`(() => {
|
|
625
|
+
const current = new URL(location.href);
|
|
626
|
+
if (/^\/in\/[^/?#]+\/?$/.test(current.pathname) && current.pathname !== '/in/me/') return current.toString();
|
|
627
|
+
const ownProfileLink = Array.from(document.querySelectorAll('a[href^="/in/"]'))
|
|
628
|
+
.map((link) => new URL(link.href, location.origin))
|
|
629
|
+
.find((url) => /^\/in\/[^/?#]+\/?$/.test(url.pathname) && url.pathname !== '/in/me/');
|
|
630
|
+
return ownProfileLink ? ownProfileLink.toString() : '';
|
|
631
|
+
})()`));
|
|
632
|
+
if (!resolvedProfileUrl) {
|
|
633
|
+
throw new CommandExecutionError('LinkedIn profile-experience could not resolve /in/me/ to a profile URL');
|
|
634
|
+
}
|
|
635
|
+
experienceUrl = profileExperienceUrl(resolvedProfileUrl);
|
|
636
|
+
} else {
|
|
637
|
+
experienceUrl = profileExperienceUrl(profileUrl);
|
|
638
|
+
}
|
|
639
|
+
await page.goto(experienceUrl);
|
|
640
|
+
await page.wait(5);
|
|
641
|
+
await assertLinkedInAuthenticated(page, 'LinkedIn profile-experience');
|
|
642
|
+
try {
|
|
643
|
+
await page.wait({ text: 'Experience', timeout: 10000 });
|
|
644
|
+
} catch {}
|
|
645
|
+
await page.autoScroll({ times: 4, delayMs: 700 });
|
|
646
|
+
await page.wait(1);
|
|
647
|
+
const payload = unwrapEvaluateResult(await page.evaluate(buildExperienceExtractionScript()));
|
|
648
|
+
if (!payload || !Array.isArray(payload.experienceRows)) {
|
|
649
|
+
throw new CommandExecutionError('LinkedIn profile-experience returned malformed extraction payload');
|
|
650
|
+
}
|
|
651
|
+
const rows = await enrichExperienceRows(page, payload.experienceRows.map(normalizeExperience));
|
|
652
|
+
if (rows.length === 0) {
|
|
653
|
+
throw new EmptyResultError('linkedin profile-experience', 'No visible LinkedIn profile experience entries were found.');
|
|
654
|
+
}
|
|
655
|
+
return rows.map((row, index) => ({ ...row, rank: index + 1, total_count: rows.length }));
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
export const __test__ = {
|
|
660
|
+
normalizeProfileUrl,
|
|
661
|
+
profileExperienceUrl,
|
|
662
|
+
decodeLinkedInSafetyUrl,
|
|
663
|
+
parseDateRangeParts,
|
|
664
|
+
parseCompanyLine,
|
|
665
|
+
parseLocationLine,
|
|
666
|
+
parseExperienceText,
|
|
667
|
+
parseExperienceSectionText,
|
|
668
|
+
buildExperienceExtractionScript,
|
|
669
|
+
buildDialogExtractionScript,
|
|
670
|
+
normalizeExperience,
|
|
671
|
+
};
|