LeetCode Solutions
Parse the community solutions tab of a LeetCode problem into structured JSON with each post title, author, tags, and engagement counts. Pricing, use cases and the other LeetCode scrapers are on the LeetCode Scraper page.
LeetCode abbreviates upvote, view, and comment counts once they pass a thousand - 11.9K, 2.3M. Those are expanded back to integers, so a value like 11900 carries the precision the page showed rather than the exact figure.
API usage
Add &scraper=leetcode-solutions 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/problems/two-sum/solutions/' \
--data-urlencode 'scraper=leetcode-solutions' -Gfrom crawlbase import CrawlingAPI
api = CrawlingAPI({'token': 'YOUR_TOKEN'})
res = api.get(
'https://leetcode.com/problems/two-sum/solutions/',
{'scraper': 'leetcode-solutions'}
)
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/problems/two-sum/solutions/',
{ scraper: 'leetcode-solutions' }
);
const data = JSON.parse(res.body);require 'crawlbase'
api = Crawlbase::API.new(token: 'YOUR_TOKEN')
res = api.get('https://leetcode.com/problems/two-sum/solutions/', scraper: 'leetcode-solutions')
data = JSON.parse(res.body)Example input URL
The solutions tab of any LeetCode problem works in the url parameter - the page at /problems/<slug>/solutions/. For example:
https://leetcode.com/problems/two-sum/solutions/
https://leetcode.com/problems/add-two-numbers/solutions/
https://leetcode.com/problems/valid-parentheses/solutions/Response shape
JSON response body. Field types may be null when the source page omits the value.
solutions for this page.Sample response
{
"url": "https://leetcode.com/problems/two-sum/solutions/",
"problem": "two-sum",
"problemUrl": "https://leetcode.com/problems/two-sum/",
"solutionCount": 15,
"solutions": [
{
"title": "Two Sum",
"url": "https://leetcode.com/problems/two-sum/solutions/127810/two-sum-by-leetcode-kwuq/",
"id": "127810",
"author": {
"name": "LeetCode",
"username": "leetcode",
"url": "https://leetcode.com/u/leetcode/"
},
"postedAt": "Jun 25, 2021",
"tags": [
"Editorial"
],
"upvotes": 5000,
"views": 13800000,
"comments": 2700
},
{
"title": "✅3 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥",
"url": "https://leetcode.com/problems/two-sum/solutions/3619262/3-methods-c-java-python-beginner-friendl-x595/",
"id": "3619262",
"author": {
"name": "Rahul Varma",
"username": "rahulvarma5297",
"url": "https://leetcode.com/u/rahulvarma5297/"
},
"postedAt": "Jun 09, 2023",
"tags": [
"Array",
"Hash Table",
"C++",
"Java"
],
"upvotes": 11900,
"views": 2300000,
"comments": 285
}
]
}