@microfox/puppeteer-linkedin
Version:
Puppeteer LinkedIn - Run puppeteer on LinkedIn
329 lines (317 loc) • 10.5 kB
TypeScript
import * as puppeteer_core from 'puppeteer-core';
import { Browser, Page, ElementHandle } from 'puppeteer-core';
declare class LinkedInPublic {
/**
* The Puppeteer browser instance.
*/
browser: Browser | null;
/**
* The Puppeteer page instance.
*/
page: Page | null;
constructor();
launch(options?: {
headless?: boolean;
}): Promise<void>;
goto(url: string, options?: Parameters<Page['goto']>[1]): Promise<puppeteer_core.HTTPResponse | null>;
close(): Promise<void>;
}
declare function scrapeArticleSection(segment: ElementHandle): Promise<ArticleSection | null>;
interface Perspective {
author: {
name: string;
headline: string;
};
text: string;
likes: number;
}
interface ArticleSection {
title: string;
content: string;
perspectives: Perspective[];
}
interface CollaborativeArticleSummary {
title: string;
url: string;
topics: {
name: string;
url: string;
}[];
}
interface FullArticle extends CollaborativeArticleSummary {
sections: ArticleSection[];
}
interface MoreToExploreTopic {
title: string;
url: string;
articles: CollaborativeArticleSummary[];
}
/**
* Retries a function with exponential backoff.
* @param {() => Promise<T>} fn The function to retry.
* @param {number} maxRetries The maximum number of retries.
* @param {number} wait The initial delay in milliseconds.
* @returns {Promise<T>}
* @template T
*/
declare function retry<T>(fn: () => Promise<T>, maxRetries?: number, wait?: number): Promise<T>;
/**
* @param {Page} page - The Puppeteer page object.
* @returns {Promise<void>}
*/
declare function handleModal(page: Page): Promise<void>;
declare function waitForUrl(page: Page, urlPart: string, timeout?: number): Promise<void>;
/**
* Scrolls the page to the bottom to trigger lazy loading of content.
* @param {Page} page - The Puppeteer page object.
* @returns {Promise<void>}
*/
declare function scrollPageToBottom(page: Page): Promise<void>;
declare module '../core/public' {
interface LinkedInPublic {
getCollaborativeArticles: (options?: {
limit?: number;
}) => Promise<CollaborativeArticleSummary[]>;
getFullCollaborativeArticles: (options?: {
limit?: number;
}) => Promise<FullArticle[]>;
scrapeArticlePage: (articleSummary: CollaborativeArticleSummary) => Promise<FullArticle | null>;
scrapeMoreToExplore: (options?: {
topicLimit?: number;
}) => Promise<MoreToExploreTopic[]>;
}
}
type EnsureLoggedIn$4 = () => Promise<void>;
type GetPage$4 = () => Page | null;
declare class LinkedInPosts {
private ensureLoggedIn;
private getPage;
protected get page(): Page | null;
constructor(ensureLoggedIn: EnsureLoggedIn$4, getPage: GetPage$4);
reactToPost(postUrl: string, reaction: 'like' | 'celebrate' | 'support' | 'love' | 'insightful' | 'funny'): Promise<void>;
commentOnPost(postUrl: string, commentText: string): Promise<void>;
createPost(text: string): Promise<void>;
}
type EnsureLoggedIn$3 = () => Promise<void>;
type GetPage$3 = () => Page | null;
declare class LinkedInJobs {
private ensureLoggedIn;
private getPage;
protected get page(): Page | null;
constructor(ensureLoggedIn: EnsureLoggedIn$3, getPage: GetPage$3);
getRecommendedJobs(limit?: number): Promise<{
title: string;
company: string;
location: string;
link: string;
}[]>;
searchJobs(options: {
keywords: string;
location: string;
}, limit?: number): Promise<{
title: string | null;
company: string | null;
location: string | null;
description: string | null;
applicantCount: string | null;
url: string;
}[]>;
}
type EnsureLoggedIn$2 = () => Promise<void>;
type GetPage$2 = () => Page | null;
declare class LinkedInUsers {
private ensureLoggedIn;
private getPage;
protected get page(): Page | null;
constructor(ensureLoggedIn: EnsureLoggedIn$2, getPage: GetPage$2);
sendConnectionRequest(profileUrl: string, message?: string): Promise<void>;
private _handleConnectionModal;
followProfile(profileUrl: string): Promise<void>;
sendConnectionRequestOrFollow(profileUrl: string, message?: string): Promise<void>;
sendMessage(profileUrl: string, message: string): Promise<void>;
getProfile(profileUrl: string): Promise<{
url: string;
name: string;
headline: string;
location: string;
about: string;
experience: any[];
education: any[];
skills: string[];
}>;
}
type Range = {
min?: number;
max?: number;
};
type CompanyHeadcount = 'Self-employed' | '1-10' | '11-50' | '51-200' | '201-500' | '501-1,000' | '1,001-5,000';
type CompanyType = 'Public Company' | 'Privately Held' | 'Non Profit' | 'Educational Institution' | 'Partnership' | 'Self Employed' | 'Self Owned' | 'Government Agency';
interface LeadSearchFilters {
keywords?: string;
currentCompany?: string | string[];
pastCompany?: string | string[];
companyHeadcount?: CompanyHeadcount[];
companyType?: CompanyType[];
companyHeadquartersLocation?: string | string[];
function?: string | string[];
currentJobTitle?: string | string[];
pastJobTitle?: string | string[];
seniorityLevel?: ('Owner' | 'Partner' | 'CXO' | 'VP' | 'Director' | 'Manager' | 'Senior' | 'Entry' | 'Training' | 'Unpaid')[];
yearsInCurrentCompany?: Range;
yearsInCurrentPosition?: Range;
geography?: string | string[];
industry?: string | string[];
firstName?: string;
lastName?: string;
profileLanguage?: string | string[];
yearsOfExperience?: Range;
groups?: string | string[];
school?: string | string[];
categoryInterest?: string | string[];
followingYourCompany?: boolean;
viewedYourProfileRecently?: boolean;
connection?: ('1st' | '2nd' | '3rd+ degree')[];
connectionsOf?: string | string[];
pastColleague?: boolean;
sharedExperiences?: boolean;
changedJobs?: boolean;
postedOnLinkedIn?: boolean;
persona?: string | string[];
accountLists?: string | string[];
leadLists?: string | string[];
peopleInCrm?: boolean;
peopleYouInteractedWith?: ('Viewed' | 'Messaged')[];
savedLeadsAndAccounts?: ('Saved leads' | 'Saved accounts' | 'All leads in saved accounts')[];
}
type EnsureLoggedIn$1 = () => Promise<void>;
type GetPage$1 = () => Page | null;
declare class LinkedInSales {
private ensureLoggedIn;
private getPage;
protected get page(): Page | null;
constructor(ensureLoggedIn: EnsureLoggedIn$1, getPage: GetPage$1);
searchForLeads(options: LeadSearchFilters): Promise<void>;
}
type EnsureLoggedIn = () => Promise<void>;
type GetPage = () => Page | null;
declare class LinkedInSearch {
private ensureLoggedIn;
private getPage;
protected get page(): Page | null;
constructor(ensureLoggedIn: EnsureLoggedIn, getPage: GetPage);
search(query: string, category: 'people' | 'jobs' | 'companies' | 'groups' | 'posts' | 'events' | 'products' | 'services' | 'schools'): Promise<{
title: string;
link: string;
summary: string;
}[]>;
private scrapePeople;
private scrapeJobs;
private scrapePosts;
private scrapeGroups;
}
declare class LinkedInAuthenticated extends LinkedInPublic {
private cookies;
isLoggedIn: boolean;
loginType: 'personal' | 'salesNavigator' | null;
private _username?;
private _password?;
private _loginOptions?;
private _posts;
private _jobs;
private _users;
private _sales;
private _search;
constructor(username?: string, password?: string, options?: {
headless?: boolean;
loginType?: 'personal' | 'salesNavigator';
});
private _ensureLoggedIn;
get posts(): LinkedInPosts;
get jobs(): LinkedInJobs;
get users(): LinkedInUsers;
get sales(): LinkedInSales;
get search(): LinkedInSearch;
private _salesNavigatorLogin;
login(username?: string, password_string?: string, options?: {
headless?: boolean;
loginType?: 'personal' | 'salesNavigator';
}): Promise<void>;
getCookies(): any;
setCookies(cookies: any): Promise<void>;
}
/**
* Represents a person's profile as found in a public search.
*/
interface Person {
/** The full name of the person. */
name: string;
/** The person's professional headline. */
headline: string;
/** The URL of the person's public profile. */
profileUrl: string;
/** The URL of the person's profile picture. */
imageUrl?: string;
/** The person's location. */
location?: string;
firstName?: string;
lastName?: string;
}
/**
* The type of search to perform.
* - 'PEOPLE': Search for people.
* - 'JOBS': Search for jobs.
* - 'LEARNING': Search for learning content.
*/
type SearchType = 'PEOPLE' | 'JOBS' | 'LEARNING';
/**
* Options for searching people.
*/
interface PeopleSearchOptions {
firstName?: string;
lastName?: string;
}
/**
* Options for searching jobs.
*/
interface JobSearchOptions {
keywords: string;
location: string;
}
interface Experience {
title: string;
company: string;
dateRange: string;
location: string;
description: string;
}
interface Education {
school: string;
degree: string;
dateRange: string;
}
interface PersonProfile extends Person {
about?: string;
experience?: Experience[];
education?: Education[];
skills?: string[];
}
declare module '../core/public' {
interface LinkedInPublic {
searchPeople: (options: PeopleSearchOptions) => Promise<Person[]>;
getProfile: (profileUrl: string) => Promise<PersonProfile>;
}
}
interface Job {
title: string;
company: string;
location: string;
url: string;
description?: string;
postedAt?: string;
}
declare module '../core/public' {
interface LinkedInPublic {
searchJobs: (options: JobSearchOptions) => Promise<Job[]>;
}
}
export { type ArticleSection, type CollaborativeArticleSummary, type Education, type Experience, type FullArticle, type Job, type JobSearchOptions, LinkedInAuthenticated, LinkedInPublic, type MoreToExploreTopic, type PeopleSearchOptions, type Person, type PersonProfile, type Perspective, type SearchType, handleModal, retry, scrapeArticleSection, scrollPageToBottom, waitForUrl };