crawlbaseDocs
Log in
Counters are rounded above a thousand

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' -G
from 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.

url
string
URL of the solutions listing that was scraped.
problem
string | null
Slug of the problem the solutions belong to.
problemUrl
string | null
Absolute URL of the problem page.
solutionCount
integer
Number of entries returned in solutions for this page.
solutions
array
Solution posts found on the page, in the order they are listed.
solutions[].title
string | null
Post title.
solutions[].url
string | null
Absolute URL of the post.
solutions[].id
string | null
Post identifier taken from its URL, returned as a string.
solutions[].author
object
Account that published the post.
solutions[].author.name
string | null
Author display name.
solutions[].author.username
string | null
Author profile handle.
solutions[].author.url
string | null
Absolute URL of the author profile.
solutions[].postedAt
string | null
Publication date as displayed on the card.
solutions[].tags
array
Tag chips on the card - topics and languages - as an array of strings.
solutions[].upvotes
integer | null
Upvote count on the post.
solutions[].views
integer | null
View count on the post.
solutions[].comments
integer | null
Comment count on the post.

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
    }
  ]
}