From 4e5fa6aa6bf31d79956300e1627ae860b4cc848b Mon Sep 17 00:00:00 2001 From: ION606 Date: Thu, 30 May 2024 15:35:16 -0400 Subject: [PATCH] added fetching company website --- classes/API.js | 7 ++++--- classes/Company.js | 8 ++++++++ classes/Profile.js | 2 +- package.json | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/classes/API.js b/classes/API.js index a1676cf..49cb75c 100644 --- a/classes/API.js +++ b/classes/API.js @@ -205,7 +205,7 @@ export default class linkedInAPIClass { const lb = (this.logAll) ? new LoadingBar(Math.round(limit / 50)) : null; - for (let i = start; i < limit; i += 50) { + for (let i = start; compAll.length < limit; i += 50) { let urlExt = `variables=(start:${i},origin:GLOBAL_SEARCH_HEADER,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(COMPANIES))${(numEmp) ? `,(key:companySize,value:List(${numsToSizes(...numEmp)}))` : ''}),includeFiltersInResponse:false))`; const r = await this._makeReq(urlExt); @@ -249,7 +249,7 @@ export default class linkedInAPIClass { if (conDeg.length) urlExt += `,(key:network,value:List(${numToConDegs(conDeg)}))`; urlExt += '),includeFiltersInResponse:false))'; - const r = await this._makeReq(urlExt); + const r = await this._makeReq(urlExt, false, true); // there's nothing left, returns what we have if (!r?.included?.length) { @@ -281,9 +281,10 @@ export default class linkedInAPIClass { * @returns {Promise} * @throws The promise will reject on error */ - async _makeReq(reqPath, isProfile = false) { + async _makeReq(reqPath, isProfile = false, ignoreTimeoutErr = false) { await this.evade(); const res = await axios.get(`https://www.linkedin.com/voyager/api/graphql?${reqPath}&queryId=${(!isProfile) ? "voyagerSearchDashClusters.f0c4f21d8a526c4a5dd0ae253c9b6e02" : "voyagerIdentityDashProfiles.5a6722404e6afd08958f5105e51cad51"}`, { headers: this.headers }).catch((err) => { + if (err?.code === 'ECONNRESET' && ignoreTimeoutErr) return null; console.error(err); return null; }); diff --git a/classes/Company.js b/classes/Company.js index 25ed9d9..0ce38e6 100644 --- a/classes/Company.js +++ b/classes/Company.js @@ -1,3 +1,5 @@ +import axios from "axios"; +import * as cheerio from 'cheerio'; import linkedInAPIClass from "../index.js"; import { LinkedInProfile } from "./Profile.js"; @@ -78,6 +80,12 @@ export class Company { this.url = data.navigationUrl; this.entityNum = data.trackingUrn.replace('urn:li:company:', ''); + axios.get(this.url).then(r => { + const $ = cheerio.load(r.data); + const u = $('a[aria-describedby="websiteLinkDescription"]')?.attr('href')?.split('url=http')?.at(1)?.split('&')[0]; + if (u) this.websiteurl = `http${decodeURIComponent(u)}`; + }).catch(_ => null); + if (!this.checkIfCompleted()) throw "NOT ALL NEEDED PARAMS FOUND!"; } } \ No newline at end of file diff --git a/classes/Profile.js b/classes/Profile.js index 1fcb475..8e4d417 100644 --- a/classes/Profile.js +++ b/classes/Profile.js @@ -16,7 +16,7 @@ export class LinkedInProfile { let { phoneNumbers, emailAddress, websites, weChatContactInfo, twitterHandles, instantMessengers } = uObj; if (websites) websites = websites.map(w => ({ label: w.label, category: w.category, url: w.url })); - return { phoneNumbers, emailAddress, websites, weChatContactInfo, twitterHandles, instantMessengers }; + return { phoneNumbers, emailAddress: (emailAddress?.emailAddress || emailAddress), websites, weChatContactInfo, twitterHandles, instantMessengers }; } // Parse specific services offered, contained in the 'simpleInsight' section of 'insightsResolutionResults' diff --git a/package.json b/package.json index 8d60eaf..736b08a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "type": "module", "name": "linkedin-api-js", - "version": "1.0.0-19", + "version": "1.0.0-20", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"