mirror of
https://github.com/ION606/linkedin-api.git
synced 2026-05-14 22:06:54 +00:00
fixed some issues with searchEmployees
This commit is contained in:
+5
-7
@@ -240,14 +240,14 @@ export default class linkedInAPIClass {
|
||||
*/
|
||||
async searchEmployees(keyword, limit = 1000, castToClass = true, filterObfuscated = true, currentCompanies = [], conDeg = []) {
|
||||
const empAll = [],
|
||||
lb = (this.logAll) ? new LoadingBar(Math.floor(limit / 10)) : null;
|
||||
lb = (this.logAll) ? new LoadingBar(Math.ceil(limit / 10)) : null;
|
||||
|
||||
for (let i = 0; empAll.length < limit; i += 50) {
|
||||
for (let i = 0; empAll.length < limit; i += 20) {
|
||||
let urlExt = `includeWebMetadata=true&variables=(start:${i},origin:FACETED_SEARCH,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(PEOPLE))`;
|
||||
|
||||
if (currentCompanies.length) urlExt += `,(key:currentCompany,value:List(${currentCompanies.join(',')}))`;
|
||||
if (conDeg.length) urlExt += `,(key:network,value:List(${numToConDegs(conDeg)}))`;
|
||||
urlExt += '),includeFiltersInResponse:false),count:50)';
|
||||
urlExt += '),includeFiltersInResponse:false))';
|
||||
|
||||
const r = await this._makeReq(urlExt);
|
||||
|
||||
@@ -263,14 +263,12 @@ export default class linkedInAPIClass {
|
||||
else return (e.template === 'UNIVERSAL' && e.title.text !== 'LinkedIn Member');
|
||||
});
|
||||
|
||||
if (this.logAll) console.log(r.included?.length, '--->', filtered.length);
|
||||
// if (this.logAll) console.error(r.included?.length, '--->', filtered.length);
|
||||
|
||||
if (filtered.length) {
|
||||
if (this.logAll) lb.increment(Math.round(filtered.length / 10));
|
||||
if (this.logAll) lb.increment(Math.ceil(filtered.length / 10));
|
||||
empAll.push(...filtered);
|
||||
}
|
||||
|
||||
await this.evade();
|
||||
}
|
||||
|
||||
if (!castToClass) return empAll;
|
||||
|
||||
+5
-6
@@ -14,19 +14,18 @@ export class Company {
|
||||
* @note This function skips over any employees who's profile is marked as private
|
||||
*/
|
||||
async getEmployees(limit = Infinity, raw = false) {
|
||||
const employeesInit = await this.#APIRef._makeReq(`variables=(start:0,origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.urn})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:1)`)
|
||||
const employeesInit = await this.#APIRef._makeReq(`variables=(start:0,origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.entityNum})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:1)`);
|
||||
|
||||
const numEmp = employeesInit.data.data.searchDashClustersByAll.paging.total,
|
||||
empAll = []
|
||||
|
||||
empAll = [];
|
||||
|
||||
// since the max cap is 50, we need to iterate until it's over 50
|
||||
for (let i = 0; i < numEmp; i += 50) {
|
||||
if (empAll.length >= limit) break;
|
||||
if (empAll.length >= limit || i >= numEmp) break;
|
||||
|
||||
const c = (i + 50 >= limit) ? limit - i : 50;
|
||||
const c = (i + 50 >= numEmp) ? numEmp - i : 50;
|
||||
|
||||
const employeeRes = await this.#APIRef._makeReq(`variables=(start:${i},origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.urn})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:${c})`);
|
||||
const employeeRes = await this.#APIRef._makeReq(`variables=(start:${i},origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.entityNum})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:${c})`);
|
||||
const employees = employeeRes.included;
|
||||
|
||||
const empParsed = employees.filter(e => (e.$type === "com.linkedin.voyager.dash.search.EntityResultViewModel"))
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"name": "linkedin-api-js",
|
||||
"version": "1.0.0-13",
|
||||
"version": "1.0.0-14",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
|
||||
+20
-6
@@ -1,15 +1,29 @@
|
||||
import LinkedInAPIClass from "../index.js";
|
||||
import fs from 'fs';
|
||||
|
||||
(async () => {
|
||||
const LAPI = new LinkedInAPIClass(true);
|
||||
const LAPI = new LinkedInAPIClass(true);
|
||||
|
||||
const o = JSON.parse(fs.readFileSync('config.json'));
|
||||
await LAPI.login(o.email, o.password);
|
||||
const o = JSON.parse(fs.readFileSync('config.json'));
|
||||
await LAPI.login(o.email, o.password);
|
||||
|
||||
async function smallTest() {
|
||||
const c = (await LAPI.searchCompanies('microsoft', [5001], 20, 0, true, true)).find(o => (o.name === 'Microsoft'));
|
||||
console.log(c);
|
||||
|
||||
|
||||
const managers = await c.searchEmployees('manager', 20);
|
||||
console.log(managers, managers.length);
|
||||
}
|
||||
|
||||
|
||||
async function largeTest() {
|
||||
const c = (await LAPI.searchCompanies('marukai', null, 1, 0, true, true)).find(o => (o.name === 'Marukai Corporation U.S.A.'));
|
||||
console.log(c);
|
||||
|
||||
console.log(await c.getEmployees());
|
||||
|
||||
const managers = await c.searchEmployees('manager');
|
||||
console.log(managers, managers.length);
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
largeTest();
|
||||
Reference in New Issue
Block a user