DEV Community

Cover image for How to Automate LinkedIn Without Getting Blocked
jacobgadek
jacobgadek

Posted on

How to Automate LinkedIn Without Getting Blocked

LinkedIn automation is a nightmare. If you've ever tried to scrape your connections or automate DMs, you know the pain:

  1. Login Scripts Fail: LinkedIn detects Selenium/Playwright login attempts instantly.
  2. 2FA is a Blocker: You can't automate the OTP step easily.
  3. Account Flagging: Repeated logins from "clean" headless browsers look suspicious.

I spent days trying to build a robust login bot. Then I realized I was solving the wrong problem.

Why hack the login door when I'm already inside?

The Solution: Session Handoff

Instead of teaching your bot to log in, you should just hand it your existing Chrome session.

Your local browser already holds the "Golden Ticket": a valid, authenticated session cookie that LinkedIn trusts. I built a tool called Romek to grab that ticket and pass it to your automation scripts.

Step-by-Step Guide

1. Install Romek

Romek is the bridge between your local Chrome browser and your Python script.

pip install romek
Enter fullscreen mode Exit fullscreen mode

2. Grab your LinkedIn Session

Run this one command in your terminal. It extracts the encrypted cookies from Chrome, decrypts them safely, and stores them in a local vault.

# This grabs cookies specifically for linkedin.com
romek grab linkedin.com
Enter fullscreen mode Exit fullscreen mode

(Note: You need to be logged into LinkedIn on Chrome for this to work)

Romekdemo

3. Inject into Playwright

Now, tell your bot to use those cookies. No username, no password, no 2FA.

from playwright.sync_api import sync_playwright
from romek import Vault

# 1. Retrieve the valid session
vault = Vault()
cookies = vault.get_session("linkedin.com")

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False) # Headless=False lets you see the magic
    context = browser.new_context()

    # 2. Inject the cookies BEFORE navigating
    context.add_cookies(cookies)

    page = context.new_page()

    # 3. Go straight to the feed
    page.goto("https://www.linkedin.com/feed/")

    # Success! You are already logged in.
    print(page.title())

    # ... insert your scraping logic here ...
Enter fullscreen mode Exit fullscreen mode

Why This is Safer

  • Residential IP Match: If you run this locally, your bot shares your exact IP address.
  • Correct Headers: You aren't generating a fresh, empty fingerprint. You are continuing an existing, trusted session.
  • Zero Credential Risk: You never hardcode your password or manage .env files for secrets.

Supports More Than Just Python

If you are into low-code automation, I also built an n8n node that does this exact same thing for workflow automation.

Links

Top comments (0)