Skip to content

Commit

Permalink
🧠 Change way that nested experience gets parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
garaekz committed Feb 4, 2023
1 parent 39935b9 commit 1fe8d6d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garaekz/inscraper",
"version": "2.0.0",
"version": "2.1.0",
"description": "A LinkedIn voyager wrapper for scraping data from LinkedIn profiles. We'll be using Playwright as a fallback and for some other functionalities.",
"main": "dist/main.js",
"types": "dist/types/main.d.ts",
Expand Down
19 changes: 7 additions & 12 deletions src/clients/voyager.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class VoyagerClient {
}
const data = await response.json();
const subExperience = data.included.find((item: any) => item.decorationType === 'NONE');
const experience = data.included.find((item: any) => item.decorationType === 'LINE_SEPARATED').components.elements.map((item: any) => this.#mapFullExperience(item, subExperience));
const experience = data.included.find((item: any) => item.decorationType === 'LINE_SEPARATED').components.elements.map((item: any) => this.#mapFullExperience(item, subExperience)).flat();
console.log(experience);

return experience;
Expand All @@ -110,30 +110,25 @@ export class VoyagerClient {
}
}

#mapFullExperience(item: any, sub?: any): Experience {
#mapFullExperience(item: any, sub?: any): Experience | Experience[] {
const base = item.components.entityComponent;
if (!base.metadata && sub) {
const originLink = base.textActionTarget;
const matching = sub.components.elements.filter((item: any) => item.components.entityComponent.textActionTarget === originLink);

const title = base.title.text;
const company = base.title.text;
const location = base.caption.text;
const tenure = base.subtitle.text;
const positions = matching.map((item: any) => {

return matching.map((item: any) => {
const base = item.components.entityComponent;
return {
title: base.title.text,
tenure: base.caption.text,
company,
location,
description: base.subComponents.components[0].components.fixedListComponent.components[0].components.textComponent.text.text
}
});

return {
title,
location,
tenure,
positions
} as Experience;
}

const title = base.title.text;
Expand Down
7 changes: 1 addition & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { PageScreenshotOptions } from "playwright";

export interface Experience {
title?: string;
title: string;
company: string;
location?: string;
tenure?: string;
positions?: {
title: string;
tenure: string;
description: string;
}[];
description?: string;
}

Expand Down

0 comments on commit 1fe8d6d

Please sign in to comment.