LeetCode Problem Set
Parse a LeetCode problem set listing into structured JSON with each problem id, title, difficulty, acceptance rate, premium flag, and URL. It is one of four LeetCode scrapers on the LeetCode Scraper API page, where you can also check pricing and start free.
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.
problems for this page.Easy, Medium, or Hard.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
}
]
}