josephlimtech / linkedin-profile-scraper-api

🕵️‍♂️ LinkedIn profile scraper returning structured profile data in JSON.
MIT License
566 stars 152 forks source link

UnhandledPromiseRejectionWarning: TypeError: linkedin_profile_scraper_1.default is not a constructor #15

Closed stvnwrgs closed 4 years ago

stvnwrgs commented 4 years ago

This first showed up, when executing my test with ts-jest. But it looks like it's a general issue.

node: v14.2.0 typescript: v3.9.5 ts-node: v8.10.1

» npx ts-node src/profile/linkedin/LinkedInCrawler.ts 
(node:58376) UnhandledPromiseRejectionWarning: TypeError: linkedin_profile_scraper_1.default is not a constructor
    at new LinkedInCrawler (/workspace/linkedin/LinkedInCrawler.ts:11:20)
    at /workspace/linkedin/LinkedInCrawler.ts:33:27
    at step (/workspace/linkedin/LinkedInCrawler.ts:33:23)
    at Object.next (/workspace/linkedin/LinkedInCrawler.ts:14:53)
    at /workspace/linkedin/LinkedInCrawler.ts:8:71
    at new Promise (<anonymous>)
    at __awaiter (/workspace/linkedin/LinkedInCrawler.ts:4:12)
    at test (/workspace/linkedin/LinkedInCrawler.ts:32:14)
    at Object.<anonymous> (/workspace/linkedin/LinkedInCrawler.ts:40:1)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
import LinkedInProfileScraper from "linkedin-profile-scraper";

class LinkedInCrawler {
  private cookie: string;
  private scraper;
  constructor(cookie) {
    this.cookie = cookie;
    this.scraper = new (LinkedInProfileScraper as any)({
      sessionCookieValue: this.cookie,
      keepAlive: true,
    });
  }

  public async loadProfileData(username: string) {
    // Prepare the scraper
    // Loading it in memory
    await this.scraper.setup();

    const result = await this.scraper.run(
      `https://www.linkedin.com/in/${username}/`
    );
    await this.scraper.close();
    return result;
  }
}

export { LinkedInCrawler };

const test = async () => {
  const linkedInCrawler = new LinkedInCrawler(
    "xxxxxxx"
  );
  const profile = await linkedInCrawler.loadProfileData("my-user");
  console.log(profile);
};

test();
jvandenaardweg commented 4 years ago

Starting from version 2.2.1, you can import it using:

Typescript:

import { LinkedinProfileScraper } from 'linkedin-profile-scraper';

Javascript:

const { LinkedinProfileScraper } = require('linkedin-profile-scraper');

See the changelog for more changes.