LeetCode Solutions
将 LeetCode 题目的社区题解标签页解析为结构化 JSON,包含每篇帖子的标题、作者、标签和互动数据。
超过一千的计数会被取整
LeetCode 会在点赞数、浏览数和评论数超过一千后进行缩写 - 例如 11.9K、2.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' -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)示例输入 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。
这些题解所属题目的 slug。
题目页面的绝对 URL。
本页在
solutions 中返回的条目数量。页面上找到的题解帖子,按其列出顺序排列。
帖子标题。
帖子的绝对 URL。
从帖子 URL 中取得的帖子标识符,以字符串返回。
发布该帖子的账号。
作者显示名称。
作者的主页用户名。
作者主页的绝对 URL。
卡片上显示的发布日期。
卡片上的标签 - 主题与语言 - 以字符串数组返回。
帖子获得的点赞数。
帖子的浏览数。
帖子的评论数。
示例响应
{
"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
}
]
}