diff --git a/classes/Company.js b/classes/Company.js index 0ce38e6..9fbf3cd 100644 --- a/classes/Company.js +++ b/classes/Company.js @@ -67,6 +67,17 @@ export class Company { } checkIfCompleted = () => !!(this.name && this.url && this.urn && this.#APIRef); + awaitCompanyURL = async () => { + try { + if (!this.url) return false; + const r = await axios.get(this.url); + 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)}`; + return true; + } + catch (err) { return false; } + } /** * @param {{title: {text: String}, entityUrn: String, navigationUrl: String}} data @@ -80,12 +91,6 @@ 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/package.json b/package.json index 736b08a..e4e5ce4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "type": "module", "name": "linkedin-api-js", - "version": "1.0.0-20", + "version": "1.0.0-21", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"