Skip to main content

LinkedIn Scraper

PyPI version Python 3.8+ License

Async LinkedIn scraper built with Playwright for extracting profile, company, and job data from LinkedIn.

⚠️ Breaking Changes in v3.0.0

Version 3.0.0 introduces breaking changes and is NOT backwards compatible with previous versions.

What Changed:

  • Playwright instead of Selenium - Complete rewrite using Playwright for better performance and reliability
  • Async/await throughout - All methods are now async and require await
  • New package structure - Imports have changed (e.g., from linkedin_scraper import PersonScraper)
  • Updated data models - Using Pydantic models instead of simple objects
  • Different API - Method signatures and return types have changed

Migration Guide:

Before (v2.x with Selenium):

from linkedin_scraper import Person

person = Person("https://linkedin.com/in/username", driver=driver)
print(person.name)

After (v3.0+ with Playwright):

import asyncio
from linkedin_scraper import BrowserManager, PersonScraper

async def main():
    async with BrowserManager() as browser:
        await browser.load_session("session.json")
        scraper = PersonScraper(browser.page)
        person = await scraper.scrape("https://linkedin.com/in/username")
        print(person.name)

asyncio.run(main())

If you need the old Selenium-based version:

pip install linkedin-scraper==2.11.2

Quick Testing

To test that this works, you can clone this repo, install dependencies with

git clone https://github.com/joeyism/linkedin_scraper.git
cd linkedin_scraper
pip3 install -e .

then run

python3 samples/create_session.py
python3 samples/scrape_company.py
python3 samples/scrape_person.py

and you will see the scraping in action.


Features

  • Person Profiles - Scrape comprehensive profile information

    • Basic info (name, headline, location, about)
    • Work experience with details
    • Education history
    • Skills and accomplishments
  • Company Pages - Extract company information

    • Company overview and details
    • Industry and size
    • Headquarters location
  • Job Listings - Scrape job postings

    • Job details and requirements
    • Company information
    • Application links
  • Async/Await - Modern async Python with Playwright

  • Type Safety - Full Pydantic models for all data

  • Progress Callbacks - Track scraping progress

  • Session Management - Reuse authenticated sessions

Installation

pip install linkedin-scraper

Install Playwright browsers:

playwright install chromium

Quick Start

Basic Usage

import asyncio
from linkedin_scraper import BrowserManager, PersonScraper

async def main():
    # Initialize browser
    async with BrowserManager(headless=False) as browser:
        # Load authenticated session
        await browser.load_session("session.json")
        
        # Create scraper
        scraper = PersonScraper(browser.page)
        
        # Scrape a profile
        person = await scraper.scrape("https://linkedin.com/in/williamhgates/")
        
        # Access data
        print(f"Name: {person.name}")
        print(f"Headline: {person.headline}")
        print(f"Location: {person.location}")
        print(f"Experiences: {len(person.experiences)}")
        print(f"Education: {len(person.educations)}")

asyncio.run(main())

Company Scraping

from linkedin_scraper import CompanyScraper

async def scrape_company():
    async with BrowserManager(headless=False) as browser:
        await browser.load_session("session.json")
        
        scraper = CompanyScraper(browser.page)
        company = await scraper.scrape("https://linkedin.com/company/microsoft/")
        
        print(f"Company: {company.name}")
        print(f"Industry: {company.industry}")
        print(f"Size: {company.company_size}")
        print(f"About: {company.about_us[:200]}...")

asyncio.run(scrape_company())

Job Scraping

from linkedin_scraper import JobSearchScraper

async def search_jobs():
    async with BrowserManager(headless=False) as browser:
        await browser.load_session("session.json")
        
        scraper = JobSearchScraper(browser.page)
        jobs = await scraper.search(
            keywords="Python Developer",
            location="San Francisco",
            limit=10
        )
        
        for job in jobs:
            print(f"{job.title} at {job.company}")
            print(f"Location: {job.location}")
            print(f"Link: {job.linkedin_url}")
            print("---")

asyncio.run(search_jobs())

Authentication

LinkedIn requires authentication. You need to create a session file first:

Option 1: Manual Login Script

from linkedin_scraper import BrowserManager, wait_for_manual_login

async def create_session():
    async with BrowserManager(headless=False) as browser:
        # Navigate to LinkedIn
        await browser.page.goto("https://www.linkedin.com/login")
        
        # Wait for manual login (opens browser)
        print("Please log in to LinkedIn...")
        await wait_for_manual_login(browser.page, timeout=300)
        
        # Save session
        await browser.save_session("session.json")
        print("✓ Session saved!")

asyncio.run(create_session())

Option 2: Programmatic Login

from linkedin_scraper import BrowserManager, login_with_credentials
import os

async def login():
    async with BrowserManager(headless=False) as browser:
        # Login with credentials
        await login_with_credentials(
            browser.page,
            username=os.getenv("LINKEDIN_EMAIL"),
            password=os.getenv("LINKEDIN_PASSWORD")
        )
        
        # Save session for reuse
        await browser.save_session("session.json")

asyncio.run(login())

Progress Tracking

Track scraping progress with callbacks:

from linkedin_scraper import ConsoleCallback, PersonScraper

async def scrape_with_progress():
    callback = ConsoleCallback()  # Prints progress to console
    
    async with BrowserManager(headless=False) as browser:
        await browser.load_session("session.json")
        
        scraper = PersonScraper(browser.page, callback=callback)
        person = await scraper.scrape("https://linkedin.com/in/williamhgates/")

asyncio.run(scrape_with_progress())

Custom Callbacks

from linkedin_scraper import ProgressCallback

class MyCallback(ProgressCallback):
    async def on_start(self, scraper_type: str, url: str):
        print(f"Starting {scraper_type} scraping: {url}")
    
    async def on_progress(self, message: str, percent: int):
        print(f"[{percent}%] {message}")
    
    async def on_complete(self, scraper_type: str, url: str):
        print(f"Completed {scraper_type}: {url}")
    
    async def on_error(self, error: Exception):
        print(f"Error: {error}")

Data Models

All scraped data is returned as Pydantic models:

Person

class Person(BaseModel):
    name: str
    headline: Optional[str]
    location: Optional[str]
    about: Optional[str]
    linkedin_url: str
    experiences: List[Experience]
    educations: List[Education]
    skills: List[str]
    accomplishments: Optional[Accomplishment]

Company

class Company(BaseModel):
    name: str
    industry: Optional[str]
    company_size: Optional[str]
    headquarters: Optional[str]
    founded: Optional[str]
    specialties: List[str]
    about: Optional[str]
    linkedin_url: str

Job

class Job(BaseModel):
    title: str
    company: str
    location: Optional[str]
    description: Optional[str]
    employment_type: Optional[str]
    seniority_level: Optional[str]
    linkedin_url: str

Advanced Usage

Browser Configuration

browser = BrowserManager(
    headless=False,  # Show browser window
    slow_mo=100,     # Slow down operations (ms)
    viewport={"width": 1920, "height": 1080},
    user_agent="Custom User Agent"
)

Error Handling

from linkedin_scraper import (
    AuthenticationError,
    RateLimitError,
    ProfileNotFoundError
)

try:
    person = await scraper.scrape(url)
except AuthenticationError:
    print("Not logged in - session expired")
except RateLimitError:
    print("Rate limited by LinkedIn")
except ProfileNotFoundError:
    print("Profile not found or private")

Best Practices

  1. Rate Limiting - Add delays between requests

    import asyncio
    await asyncio.sleep(2)  # 2 second delay
    
  2. Session Reuse - Save and reuse sessions to avoid frequent logins

  3. Error Handling - Always handle exceptions (rate limits, auth errors, etc.)

  4. Headless Mode - Use headless=False during development, True for production

  5. Respect LinkedIn - Don't scrape aggressively, respect rate limits

Requirements

  • Python 3.8+
  • Playwright
  • Pydantic 2.0+
  • aiofiles
  • python-dotenv (optional, for credentials)

License

Apache License 2.0 - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Disclaimer

This tool is for educational purposes only. Make sure to comply with LinkedIn's Terms of Service and use responsibly. The authors are not responsible for any misuse of this tool.

Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linkedin_scraper-3.1.0.tar.gz (46.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linkedin_scraper-3.1.0-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

File details

Details for the file linkedin_scraper-3.1.0.tar.gz.

File metadata

  • Download URL: linkedin_scraper-3.1.0.tar.gz
  • Upload date:
  • Size: 46.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for linkedin_scraper-3.1.0.tar.gz
Algorithm Hash digest
SHA256 830bd3a4c16aeb667f5a00c0eed7528c80e0b360016f4c8eecd9cebad0d8728e
MD5 58cd86532bf6723f45a21d53b293d452
BLAKE2b-256 d230967d78a67bc974e65491582e23993ca078d47c7b634842af13c8422162b9

See more details on using hashes here.

File details

Details for the file linkedin_scraper-3.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for linkedin_scraper-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e3ad52cd858d25034cab5f82261bfe35451941faec6003714aff2e745939212
MD5 88c1c7e8bc644fa76d23837201a0ac42
BLAKE2b-256 3fa7ce6de57a4bd75bfadaa23fb8f3eaa0b86de779335c13be08f8bbf3846438

See more details on using hashes here.

Release history Release notifications | RSS feed

3.1.2

2 files

3.1.1

2 files

This release

3.1.0 This release

2 files

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.11.5

2 files

2.11.4

2 files

2.11.3

2 files

2.11.2

2 files

2.11.1

2 files

2.11.0

2 files

2.10.1

2 files

2.10.0

2 files

2.9.2

2 files

2.9.1

2 files

2.9.0

2 files

2.8.2

2 files

2.8.1

2 files

2.8.0

2 files

2.7.7

2 files

2.7.6

2 files

2.7.5

2 files

2.7.4

2 files

2.7.3

2 files

2.7.2

2 files

2.7.1

2 files

2.7.0

2 files

2.6.1

2 files

2.6.0

2 files

2.5.5

2 files

2.5.4

2 files

2.5.3

2 files

2.5.2

2 files

2.5.1

2 files

2.5.0

2 files

2.4.6

2 files

2.4.5

2 files

2.4.4

2 files

2.4.3

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

1 file

2.1.1

1 file

2.1.0

2 files

2.0.1

1 file

2.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page