LeetCode Problem Set
Parse a LeetCode problem set listing into structured JSON with each problem id, title, difficulty, acceptance rate, premium flag, and URL.
The daily challenge is returned as an extra row
LeetCode pins the daily challenge above the paginated table, so a full page returns one entry more than the page size - the pinned problem first, then the table rows. It is the only entry with isDailyQuestion set to true, which makes it straightforward to drop if you only want the table.
API usage
Add &scraper=leetcode-serp to a Crawling API request. URL-encode the target URL in the url parameter.
curl 'https://api.crawlbase.com/?token=YOUR_TOKEN' \
--data-urlencode 'url=https://leetcode.com/problemset/' \
--data-urlencode 'scraper=leetcode-serp' -Gfrom crawlbase import CrawlingAPI
api = CrawlingAPI({'token': 'YOUR_TOKEN'})
res = api.get(
'https://leetcode.com/problemset/',
{'scraper': 'leetcode-serp'}
)
import json
data = json.loads(res['body'])const { CrawlingAPI } = require('crawlbase');
const api = new CrawlingAPI({ token: 'YOUR_TOKEN' });
const res = await api.get(
'https://leetcode.com/problemset/',
{ scraper: 'leetcode-serp' }
);
const data = JSON.parse(res.body);require 'crawlbase'
api = Crawlbase::API.new(token: 'YOUR_TOKEN')
res = api.get('https://leetcode.com/problemset/', scraper: 'leetcode-serp')
data = JSON.parse(res.body)Example input URL
Any LeetCode problem set listing works in the url parameter - the unfiltered set at /problemset/ or a filtered view. For example:
https://leetcode.com/problemset/
https://leetcode.com/problemset/?difficulty=EASY
https://leetcode.com/problemset/?topicSlugs=dynamic-programmingResponse shape
JSON response body. Field types may be null when the source page omits the value.
URL of the problem set listing that was scraped.
Total number of problems LeetCode reports for the current filter, across every page.
Number of entries returned in
problems for this page.Problem rows found on the page, in the order they are listed.
Problem number as shown in the listing, returned as a string.
Problem display title.
URL slug of the problem, usable to build any other LeetCode problem URL.
Absolute URL of the problem page.
Difficulty label -
Easy, Medium, or Hard.Acceptance rate as displayed, including the percent sign.
Whether the problem is locked behind a LeetCode subscription.
Whether this row is the pinned daily challenge.
Sample response
{
"url": "https://leetcode.com/problemset/",
"totalProblems": 4013,
"problemCount": 101,
"problems": [
{
"id": "3626",
"title": "Smallest Divisible Digit Product I",
"titleSlug": "smallest-divisible-digit-product-i",
"url": "https://leetcode.com/problems/smallest-divisible-digit-product-i",
"difficulty": "Easy",
"acceptanceRate": "71.0%",
"isPremium": false,
"isDailyQuestion": true
},
{
"id": "1",
"title": "Two Sum",
"titleSlug": "two-sum",
"url": "https://leetcode.com/problems/two-sum",
"difficulty": "Easy",
"acceptanceRate": "57.9%",
"isPremium": false,
"isDailyQuestion": false
},
{
"id": "2",
"title": "Add Two Numbers",
"titleSlug": "add-two-numbers",
"url": "https://leetcode.com/problems/add-two-numbers",
"difficulty": "Medium",
"acceptanceRate": "49.1%",
"isPremium": false,
"isDailyQuestion": false
}
]
}