crawlbase文档
登录
超过一千的计数会被取整

LeetCode 会在点赞数、浏览数和评论数超过一千后进行缩写 - 例如 11.9K2.3M。这些值会被还原为整数,因此像 11900 这样的数值反映的是页面显示的精度,而非确切数字。

API 用法

Crawling API 请求中加上 &scraper=leetcode-solutions。目标 URL 需经过 URL 编码后放入 url 参数。

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)

示例输入 URL

url 参数支持任意 LeetCode 题目的题解标签页 - 即 /problems/<slug>/solutions/ 的页面。例如:

https://leetcode.com/problems/two-sum/solutions/
https://leetcode.com/problems/add-two-numbers/solutions/
https://leetcode.com/problems/valid-parentheses/solutions/

响应结构

JSON 响应体。当源页面省略对应值时,字段类型可能为 null

url
string
被抓取的题解列表的 URL。
problem
string | null
这些题解所属题目的 slug。
problemUrl
string | null
题目页面的绝对 URL。
solutionCount
integer
本页在 solutions 中返回的条目数量。
solutions
array
页面上找到的题解帖子,按其列出顺序排列。
solutions[].title
string | null
帖子标题。
solutions[].url
string | null
帖子的绝对 URL。
solutions[].id
string | null
从帖子 URL 中取得的帖子标识符,以字符串返回。
solutions[].author
object
发布该帖子的账号。
solutions[].author.name
string | null
作者显示名称。
solutions[].author.username
string | null
作者的主页用户名。
solutions[].author.url
string | null
作者主页的绝对 URL。
solutions[].postedAt
string | null
卡片上显示的发布日期。
solutions[].tags
array
卡片上的标签 - 主题与语言 - 以字符串数组返回。
solutions[].upvotes
integer | null
帖子获得的点赞数。
solutions[].views
integer | null
帖子的浏览数。
solutions[].comments
integer | null
帖子的评论数。

示例响应

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