crawlbaseDocs
Log in
Only the rendered code blocks are returned

Many posts advertise several languages but put the alternatives behind tabs that render one at a time. codeBlocks holds the blocks present in the write-up as served, so a post titled for three languages can come back with blocks in one.

API usage

Add &scraper=leetcode-solution 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/3619262/3-methods-c-java-python-beginner-friendl-x595/' \
  --data-urlencode 'scraper=leetcode-solution' -G
from crawlbase import CrawlingAPI

api = CrawlingAPI({'token': 'YOUR_TOKEN'})
res = api.get(
    'https://leetcode.com/problems/two-sum/solutions/3619262/3-methods-c-java-python-beginner-friendl-x595/',
    {'scraper': 'leetcode-solution'}
)

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/3619262/3-methods-c-java-python-beginner-friendl-x595/',
  { scraper: 'leetcode-solution' }
);
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/3619262/3-methods-c-java-python-beginner-friendl-x595/', scraper: 'leetcode-solution')
data = JSON.parse(res.body)

Example input URL

Any LeetCode community solution post works in the url parameter - the page at /problems/<slug>/solutions/<id>/<post-slug>/. For example:

https://leetcode.com/problems/two-sum/solutions/3619262/3-methods-c-java-python-beginner-friendl-x595/
https://leetcode.com/problems/two-sum/solutions/127810/two-sum-by-leetcode-kwuq/

Response shape

JSON response body. Field types may be null when the source page omits the value.

url
string
URL of the solution post that was scraped.
id
string | null
Post identifier taken from its URL, returned as a string.
problem
string | null
Slug of the problem the post belongs to.
problemUrl
string | null
Absolute URL of the problem page.
title
string | null
Post title.
author
object
Account that published the post.
author.name
string | null
Author display name.
author.username
string | null
Author profile handle.
author.url
string | null
Absolute URL of the author profile.
postedAt
string | null
Publication date as displayed on the post.
tags
array
Tag chips on the post - topics and languages - as an array of strings.
views
integer | null
View count on the post.
upvotes
integer | null
Upvote count on the post.
comments
integer | null
Comment count on the post.
content
string | null
The write-up flattened to plain text.
contentHtml
string | null
The write-up as HTML, with headings, lists, and code markup preserved.
codeBlocks
array
Code blocks extracted from the write-up, in document order.
codeBlocks[].language
string | null
Language of the block as LeetCode labels it, for example cpp.
codeBlocks[].code
string | null
The block source, with its original indentation.

Sample response

{
  "url": "https://leetcode.com/problems/two-sum/solutions/3619262/3-methods-c-java-python-beginner-friendl-x595/",
  "id": "3619262",
  "problem": "two-sum",
  "problemUrl": "https://leetcode.com/problems/two-sum/",
  "title": "✅3 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥",
  "author": {
    "name": "Rahul Varma",
    "username": "rahulvarma5297",
    "url": "https://leetcode.com/u/rahulvarma5297/"
  },
  "postedAt": "Jun 09, 2023",
  "tags": [
    "Array",
    "Hash Table",
    "C++",
    "Java"
  ],
  "views": 2368905,
  "upvotes": 12000,
  "comments": 285,
  "content": "Intuition\n\nThe Two Sum problem asks us to find two numbers in an array that sum up to a given target value. We need to r...",
  "contentHtml": "

Intuition

\n\n

The Two Sum problem asks us to find two numbers in an array that sum up to a given...", "codeBlocks": [ { "language": "cpp", "code": "class Solution {\npublic:\n vector twoSum(vector& nums, int target) {\n int n = nums.size();\n..." } ] }