Alert

DEPRECATED: This actor is no longer actively maintained.

Actor picture

Example Linkedin Sign In

drobnikj/linkedin-sign-in-example

Shows you how to sign in to LinkedIn with an Apify actor with Puppeteer image. Note that it does not solve the anti-captcha.

No credit card required

Author's avatarJakub Drobn铆k
  • Modified
  • Users69
  • Runs1,446
Actor picture

Example Linkedin Sign In

Based on the apify/actor-node-puppeteer Docker image (see docs).

This file is 180 lines long. Only the first 50 are shown. Show all

const Apify = require('apify');

const humanDelay = ms => (Math.random() + 1) * ms;

const saveScreen = async (page, key) => {
    const screenshotBuffer = await page.screenshot();
    await Apify.setValue(key, screenshotBuffer, { contentType: 'image/png' });
};

/**
 * Use this class for sign in to linkedin
 * NOTE: linkedin sometimes can verified user with pin, which is sent to user email. In this case
 * forward email to 8mxmzpus@robot.zapier.com. It is email parser, which send pin direct to act.
 * usage: const browser = await Apify.launchPuppeteer({ proxyUrl: proxy.href, headless: true });
 * const page = await browser.newPage(); const linkedinUtils = new LinkedinUtils(page, user, pwd)
 * linkedinUtils.login();
 */
class LinkedinUtils {
    /**
     * @param page - instance of puppeteer page object
     * @param user - linkedin user
     * @param pwd - linkedin user password
     */
    constructor(page, user, pwd, debugMode = false) {
        this.page = page;
        this.user = user;
        this.pwd = pwd;
        this.loginPageUrl = 'https://www.linkedin.com/';
        this.debugMode = debugMode;
        this.signInCount = 0;
    }

    async login() {
        console.log('Sign in ...');
        if (this.signInCount > 5) {
            throw new Error('Failed to sign in, check user and password');
            return;
        }
        await this.page.goto(this.loginPageUrl);
        const userInput = await this.page.$('#login-email');
        await userInput.type(this.user, humanDelay(100));
        const pwdInput = await this.page.$('#login-password');
        await pwdInput.type(this.pwd, { delay: humanDelay(100) });
        await this.page.click('#login-submit', { delay: humanDelay(100) });
        await new Promise(resolve => setTimeout(resolve, humanDelay(5000)));

        // Page can contain verification code
        const isVerifCode = await this.isVerifCode();
        if (isVerifCode) await this.fillVerifCode();