Guide

How to Scrape LinkedIn with Python in 2026: A Self-Built Scraper or a Profile API

What each route asks of a Python developer, what LinkedIn's own terms say, and a complete requests script that creates a run, polls it, pages through the results and writes a CSV.

Last updated · 9 min read

There are two ways to get LinkedIn profile data into Python: write and run your own scraper, or call a third-party profile data API with an HTTP library such as requests. A self-built scraper means keeping a browser, logged-in sessions and HTML parsing working as LinkedIn changes its pages, and LinkedIn's User Agreement prohibits software that scrapes profiles from its services. A profile API moves that work to the provider: your Python code sends filters or profile URLs, waits for the job to finish and reads structured JSON. LinkedIn's official API, which has an official Python client, returns only the data of the member who signs in to your app.

What is LinkedIn scraping with Python?

LinkedIn scraping with Python is the practice of collecting LinkedIn profile data, such as names, headlines, job titles, companies and work history, into a Python program instead of copying it by hand. The data can come from code that loads LinkedIn pages and parses them, or from an API that returns the profiles as JSON.

The difference matters for what a Python developer ends up owning. With a scraper, the Python code itself fetches and parses LinkedIn pages. With an API, the Python code is an ordinary HTTP client: it authenticates, sends a request, handles errors and stores the response.

A typical case is a recruiting-analytics startup that needs every Backend Engineer in the Netherlands in a Postgres table each week. Both routes can feed that table; they differ in how much code has to be kept alive between one week and the next.

What a self-built Python LinkedIn scraper has to maintain

A self-built Python LinkedIn scraper has to maintain four moving parts: a browser or HTTP session, usually signed in as a LinkedIn member; the navigation that finds the right pages; the parser that turns HTML into fields; and the storage and deduplication around them. Each part breaks independently when LinkedIn changes its pages.

The parser is the part that fails most quietly. A Python script that reads a job title from a page element keeps running when that element moves, and it starts writing empty or wrong values into the table instead of raising an error.

The session is the part that ties the scraper to a person. A scraper that browses as a signed-in member acts through that member's LinkedIn account, so the account's standing depends on what the script does.

Unofficial Python packages that skip the browser have the same dependency. The linkedin-api package on PyPI, for example, says on its project page that it needs a valid LinkedIn user account, that it is not officially supported by LinkedIn and that using it might violate LinkedIn's Terms of Service. Whether to build or buy is a wider decision than Python alone; this guide covers what each route looks like in code.

What LinkedIn's User Agreement says about scraping

LinkedIn's User Agreement, effective on 3 November 2025, lists in section 8.2 ("Don'ts") that members agree not to develop, support or use software, scripts, robots, crawlers or browser plugins to "scrape or copy the Services, including profiles and other data from the Services". The same section also covers using another person's account and using bots to access the services.

Those terms bind the LinkedIn member whose account a scraper uses. A Python team that wants profile data without lending its own LinkedIn account to a script can use a provider that does not ask for one, and it still needs its own lawful basis for collecting and using personal data under laws such as the EU GDPR. The full text is in LinkedIn's User Agreement.

LinkedIn API in Python: the official client library

LinkedIn publishes an official Python client, linkedin-api-client on PyPI, which its PyPI page describes as a thin client for LinkedIn's APIs built on the requests library. Version 0.3.0, uploaded to PyPI in June 2023, requires Python 3.7 or later, handles 2-legged and 3-legged OAuth 2.0, and is labelled beta: its README says it is subject to change and asks for caution in production.

The client library does not widen what the official LinkedIn API returns. Its own getting-started example uses the self-serve Sign In with LinkedIn product to fetch the current member's profile, and richer data, such as ad accounts, needs a product that LinkedIn approves.

For a Python developer, pip install linkedin-api-client is the right tool for a login button or an approved partner integration, not for reading other people's profiles. The products, scopes and limits are covered in the guide to what the official LinkedIn API returns.

Self-built scraper vs profile API in Python (2026)

A self-built scraper and a profile API differ less in the Python code than in what that code depends on. The table sets them side by side, with the official API as the third route a Python developer meets.

Route in Python What your code does LinkedIn account needed Whose profiles What you maintain Cost or access
Profile API (pineapi) Sends filters or URLs with requests, polls a run, reads JSON No Profiles matching filters, or the URLs you send An HTTP client and your storage $0.010 per profile delivered, $0.12 minimum per search
Self-built scraper Drives a browser or session, parses HTML Usually, a signed-in member Whatever the session can open Browser, session, parser, storage Your infrastructure and engineering time
Official LinkedIn API (linkedin-api-client) Runs OAuth 2.0, calls documented endpoints Yes, each member signs in The signed-in member, or partner data OAuth flow and token renewal Self-serve login and posting; partner data needs LinkedIn approval

pineapi's figures come from its pricing and billing rules; providers that bill per record or by subscription are compared on their own units in a side-by-side review of scraper APIs.

How to scrape LinkedIn profiles with Python through an API

To get LinkedIn profiles into Python through an API, create a run with a POST request, poll the run until it reaches a final status, then page through the profiles with a cursor and write them where you need them. pineapi, an API that finds LinkedIn profiles by filters or URLs and bills per profile delivered, works this way, and the four steps below are a complete script with requests.

A pineapi key is a bearer token; the API never asks for a LinkedIn login or session cookie. The examples read the API host and key from PINEAPI_BASE_URL and PINEAPI_KEY; how to get both is in the pineapi API quickstart.

Step 1: Create a search run with an Idempotency-Key

A pineapi search is created with POST /v1/profile-searches, and the response is HTTP 202 with a run_id, not the profiles. The Idempotency-Key header is required: keep the same key and body if the request is retried, so a network error never starts a second paid search.

This request is paid. With max_items set to 100, it costs at most $1.00 (100 profiles × $0.010), and a search that completes with no matches costs the $0.12 minimum. max_items goes from 25 to 2,000 in multiples of 25, and exact location values come from /v1/catalogs/locations.

This code creates the search and keeps its run_id:

import os, time, uuid
import requests

BASE = os.environ["PINEAPI_BASE_URL"].rstrip("/") + "/v1"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['PINEAPI_KEY']}"

def call(method, path, **kwargs):
    while True:
        response = session.request(method, BASE + path, timeout=30, **kwargs)
        if response.status_code == 429:  # rate limited: wait as instructed
            time.sleep(int(response.headers.get("Retry-After", "5")))
            continue
        response.raise_for_status()
        return response.json()

body = {"current_job_titles": ["Backend Engineer"], "locations": ["Netherlands"], "max_items": 100}
key = str(uuid.uuid4())  # store it with the body to retry the same request safely
run_id = call("POST", "/profile-searches", json=body, headers={"Idempotency-Key": key})["run_id"]
print("run_id:", run_id)

Every request sets a timeout, because the requests documentation warns that without one a program can hang indefinitely.

Step 2: Poll the run until it finishes

A pineapi run is polled with GET /v1/runs/{run_id} at 5-second intervals during the first minute, then at 20-second intervals, until its status is succeeded, partial, failed or cancelled. URL lookups usually take seconds and searches minutes, according to pineapi's documentation, which presents those times as observations rather than a guarantee.

This loop waits for a final status and stops on failed or cancelled, which are not billed:

started = time.monotonic()
while True:
    run = call("GET", f"/runs/{run_id}")
    if run["status"] not in {"queued", "starting", "running", "processing"}:
        break
    if time.monotonic() - started > 1800:
        raise TimeoutError(f"Still running; resume polling run_id {run_id}")
    time.sleep(5 if time.monotonic() - started < 60 else 20)

if run["status"] not in {"succeeded", "partial"}:
    raise RuntimeError(run.get("failure") or run["status"])
print(run["status"], run["profiles_delivered"], "profiles, charged", run["charged"]["usd"])

partial is a normal final status in pineapi: fewer profiles arrived than were requested, and only the delivered ones are billed.

Step 3: Read every page with next_cursor

pineapi returns a finished run's profiles from GET /v1/runs/{run_id}/profiles, one page at a time. Each page has data, has_more and next_cursor; the next request sends next_cursor as its cursor parameter, and the loop ends when has_more turns false. There is no offset, and reading results again costs nothing.

This loop collects every profile of the run into a list:

profiles, params = [], {"limit": 200}
while True:
    page = call("GET", f"/runs/{run_id}/profiles", params=params)
    profiles.extend(page["data"])
    if not page["has_more"]:
        break
    params["cursor"] = page["next_cursor"]
print(len(profiles), "profiles read")

Each pineapi profile carries 53 fields and 16 nested collections, such as experiences, education and skills, and no email address. The full list is in the pineapi response schema.

Step 4: Save the profiles to CSV

A Python script can write pineapi profiles to CSV with the standard library's csv.DictWriter, choosing the flat fields it needs. Setting extrasaction="ignore" makes DictWriter skip the keys that are not in fieldnames instead of raising ValueError, its default behaviour according to the Python documentation.

This code writes one row per profile, including the two truncation flags:

import csv

fields = ["full_name", "headline", "current_title", "current_company_name",
          "location_text", "linkedin_url", "total_months_experience",
          "experience_truncated", "skills_truncated"]
with open("profiles.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=fields, extrasaction="ignore")
    writer.writeheader()
    writer.writerows(profiles)

pineapi also serves the same run as CSV from GET /v1/runs/{run_id}/profiles.csv, with the API key, for teams that do not need to pick columns in Python.

LinkedIn scraping in Python: best practices for data you can trust

The best practices for LinkedIn profile data in Python are about the data, not the HTTP calls: check whether each profile arrived complete, size searches so pages do not overlap, keep the request that started each run, and store results before they expire. pineapi publishes the numbers behind each one.

  • Check the truncation flags before computing tenure. In pineapi's data, 40% of LinkedIn profiles arrive with truncated work history and 68% with truncated skills, so total_months_experience can be an undercount; filter or flag rows where experience_truncated is true.
  • Ask for one large search instead of several small pages. pineapi measured about 30% overlap between consecutive paginated calls of the same LinkedIn search, and duplicates across separate runs are billed again, so one run with a higher max_items returns more for less.
  • Join URL lookups on requested_url. When the input is a list of profile URLs, POST /v1/profile-lookups takes up to 2,000 per request, and each returned pineapi profile carries requested_url; the current linkedin_url may have a different slug. Unresolved URLs come back in the run's unresolved list and are not billed.
  • Respect the rate limits in the client. pineapi's documentation allows 60 run creations per minute, with bursts of 120, shared across an account's keys; HTTP 429 carries Retry-After in seconds, which the call() helper above already honours.
  • Copy results out within 30 days. pineapi keeps a run's results for 30 days and then deletes them, so the Python job should write them to its own storage on the day it runs.

pineapi is not affiliated with LinkedIn. Whoever runs the script decides what personal data to keep and needs a lawful basis of their own for storing and using it.