Building custom technical interview platforms, curriculum generators, or competitive programming analytics dashboards requires structured problem data. Manual collection or ad-hoc scraping of LeetCode quickly hits complexity around dynamic frontend rendering and non-standard GraphQL endpoints. Collecting problem metadata—such as difficulty ratings, acceptance rates, and primary topic tags—demands a repeatable ingestion pipeline that handles pagination and schema filtering natively.
The LeetCode Scraper automates this collection process. It interfaces directly with public data endpoints, extracting core problem attributes without requiring user session cookies, login credentials, or third-party API keys.
Schema Inputs and Filtering Strategies
Extracting technical problem data efficiently relies on passing the correct input parameters to avoid scraping unnecessary items. The scraper operates under two main execution modes defined by the mode parameter: problems for bulk listing and searching, and problem for targeting a single problem instance.
When retrieving lists of questions (mode="problems"), the input schema supports several targeted filters to narrow down the dataset before records are emitted:
-
difficulty: Filters the target questions by official difficulty level. Acceptable values are""(all levels),"EASY","MEDIUM", or"HARD". -
topic: Filters by the canonical LeetCode topic slug. Valid options include"array","string","hash-table","dynamic-programming","math","sorting","greedy","depth-first-search","binary-search","database","breadth-first-search","tree","matrix","two-pointers","binary-tree","bit-manipulation","stack","heap-priority-queue", and"graph". -
searchQuery: Accepts a string to match against question title keywords. -
skipPaidOnly: A boolean flag. Setting this totrueexcludes premium-only questions, ensuring the dataset only contains publicly accessible tasks. -
maxItems: An integer that acts as a hard cap on the total number of records emitted during the run.
Extracting Dynamic Programming Problems
If you need to extract up to 100 free, medium-difficulty dynamic programming problems, pass the following JSON payload into the run configuration:
{
"mode": "problems",
"difficulty": "MEDIUM",
"topic": "dynamic-programming",
"skipPaidOnly": true,
"maxItems": 100
}
Direct Lookups via Problem Slugs
To inspect a single problem, set mode to "problem" and supply the exact URL identifier in problemSlug. For instance, targeting the classic Two Sum problem uses this configuration:
{
"mode": "problem",
"problemSlug": "two-sum"
}
Structure of the Output Dataset
Every record generated by the Actor yields a standard payload containing identifying metadata, difficulty details, and canonical URL references. The fields present in each record include:
-
questionFrontendId: The public problem number displayed on the platform (e.g.,"1"). -
title: The full text name of the problem (e.g.,"Two Sum"). -
difficulty: The categorical rating ("Easy","Medium", or"Hard"). -
acceptanceRate: The float value representing the historical percentage of accepted submissions against total submissions. -
topics: An array of associated topic tag objects or strings attached to the question. -
problemUrl: The fully qualified web address leading to the problem statement.
A typical JSON output record retrieved from the default dataset follows this structure:
{
"questionFrontendId": "1",
"title": "Two Sum",
"difficulty": "Easy",
"acceptanceRate": 52.3,
"topics": ["Array", "Hash Table"],
"problemUrl": "https://leetcode.com/problems/two-sum/",
"recordType": "record",
"scrapedAt": "2024-01-15T10:30:00+00:00"
}
Step-by-Step Implementation Guide
Running the scraper via Python to populate an internal data store involves initializing the Apify client, executing the Actor with explicit inputs, and reading the resulting dataset.
- Install the Client Library: Ensure the official SDK is installed in your virtual environment.
pip install apify-client
-
Configure and Execute the Run: Instantiate
ApifyClientand pass the parameter block matching your dataset requirements.
from apify_client import ApifyClient
# Initialize client without hardcoded keys using standard env vars
client = ApifyClient()
run_input = {
"mode": "problems",
"difficulty": "HARD",
"topic": "graph",
"skipPaidOnly": True,
"maxItems": 50
}
# Run the Actor and wait for completion
run = client.actor("crawlerbros/leetcode-scraper").call(run_input=run_input)
# Fetch results from the run's default dataset
dataset_items = client.dataset(run["defaultDatasetId"]).list_items().items
for item in dataset_items:
print(f"[{item.get('questionFrontendId')}] {item.get('title')} - Acceptance: {item.get('acceptanceRate')}%")
- Incorporate Output into Pipelines: Parse the returned list directly into pandas DataFrames, write them to database targets, or serialize them as flat files.
Event Pricing and Cost Mechanics
The pricing structure for this Actor relies on a PAY_PER_EVENT model. Runs are billed based on discrete event charges combined with platform usage costs.
Event Charges
The platform charges event fees directly tied to Actor execution and output volume:
- Actor Start (
apify-actor-start): Charged once per run at a flat base price of $0.005 per GB of memory allocated to the run. - Result (
apify-default-dataset-item): Charged for each individual record generated and written to the default dataset.
The base tier price for the result event is $0.005 per record under the standard FREE tier. Accounts participating in platform discount tiers pay reduced rates per result item:
- FREE: $0.005 per result
- BRONZE: $0.00433 per result
- SILVER: $0.00367 per result
- GOLD: $0.003 per result
- PLATINUM: $0.003 per result
- DIAMOND: $0.003 per result
Estimating Total Run Expenses
Calculating the total financial cost of a scraping job requires accounting for both billed events and the underlying platform usage. Platform usage is tracked separately based on the specific rates of your active Apify plan.
For example, pulling 100 problem records on a default memory allocation incurring standard FREE tier charges costs $0.005 for the Actor Start event ($0.005 per GB) plus $0.50 for the 100 result events (100 × $0.005), alongside any additional platform usage consumed during execution time.
Operational Boundaries
This tool focuses exclusively on public problem metadata and listing metrics; it does not scrape user submission histories, source code solutions, hidden test cases, or private account data.
The examples here were produced with LeetCode Scraper. Its README lists the output fields, so you can check a response against the schema before you build on it.
Prices quoted above are this Actor's published pay-per-event rates on the Apify Store, read from the Apify platform API on 2026-09-25. Check the Actor page for the current rates.
Top comments (0)