Crawling API / LeetCode

LeetCode 抓取工具。
题目与题解,完整渲染。

发送任意 LeetCode URL,即可获得完整渲染的 HTML,通过住宅代理并内置反爬处理。
或使用 leetcode-serp、leetcode-problem、leetcode-solutions 和 leetcode-solution 抓取工具获取结构化 JSON。

99% 成功率1.4 亿住宅 IP30 个地区
LeetCode URLHTML or JSONleetcode.com/problems/two-sum/Crawlbase路由渲染提取渲染后的 HTML题库题目题解列表单篇题解crawling-apileetcode-serpleetcode-problemleetcode-solutionsleetcode-solutionleetcode.com · 渲染 + 解析 · 200
实时抓取流 · LeetCode1.24M req/min流式传输
200leetcode.com/problems/valid-parentheses/solutions/GB215ms
200leetcode.com/problemset/AU48ms
404leetcode.com/problemset/?difficulty=EASYBR63ms
200leetcode.com/problems/two-sum/BR181ms
200leetcode.com/problems/best-time-to-buy-and-sell-stock/CA219ms
200leetcode.com/problems/climbing-stairs/solutions/GB83ms
200leetcode.com/problems/add-two-numbers/NL55ms
200leetcode.com/problemset/GB169ms
200leetcode.com/problems/two-sum/BR109ms
200leetcode.com/problemset/?topicSlugs=arrayBR92ms
200leetcode.com/problems/merge-two-sorted-lists/solutions/ES117ms
301leetcode.com/problemset/?page=2CA99ms
200leetcode.com/problemset/?difficulty=EASYUS105ms
200leetcode.com/problems/valid-parentheses/solutions/FR97ms
200leetcode.com/problemset/?page=2IN158ms
404leetcode.com/problemset/?status=NOT_STARTEDJP126ms
200leetcode.com/problemset/DE99ms
200leetcode.com/problemset/?difficulty=EASYAU200ms
200leetcode.com/problemset/US84ms
200leetcode.com/problemset/?page=2SG71ms
301leetcode.com/problemset/?page=2DE95ms
200leetcode.com/problemset/?difficulty=EASYUS57ms
200leetcode.com/problems/two-sum/solutions/NL113ms
200leetcode.com/problemset/?topicSlugs=arrayAU61ms
200leetcode.com/problemset/?page=2GB90ms
200leetcode.com/problemset/SG88ms
200leetcode.com/problems/valid-parentheses/solutions/GB215ms
200leetcode.com/problemset/AU48ms
404leetcode.com/problemset/?difficulty=EASYBR63ms
200leetcode.com/problems/two-sum/BR181ms
200leetcode.com/problems/best-time-to-buy-and-sell-stock/CA219ms
200leetcode.com/problems/climbing-stairs/solutions/GB83ms
200leetcode.com/problems/add-two-numbers/NL55ms
200leetcode.com/problemset/GB169ms
200leetcode.com/problems/two-sum/BR109ms
200leetcode.com/problemset/?topicSlugs=arrayBR92ms
200leetcode.com/problems/merge-two-sorted-lists/solutions/ES117ms
301leetcode.com/problemset/?page=2CA99ms
200leetcode.com/problemset/?difficulty=EASYUS105ms
200leetcode.com/problems/valid-parentheses/solutions/FR97ms
200leetcode.com/problemset/?page=2IN158ms
404leetcode.com/problemset/?status=NOT_STARTEDJP126ms
200leetcode.com/problemset/DE99ms
200leetcode.com/problemset/?difficulty=EASYAU200ms
200leetcode.com/problemset/US84ms
200leetcode.com/problemset/?page=2SG71ms
301leetcode.com/problemset/?page=2DE95ms
200leetcode.com/problemset/?difficulty=EASYUS57ms
200leetcode.com/problems/two-sum/solutions/NL113ms
200leetcode.com/problemset/?topicSlugs=arrayAU61ms
200leetcode.com/problemset/?page=2GB90ms
200leetcode.com/problemset/SG88ms
01 实时演示

四个 LeetCode 抓取工具。每个都返回干净的 JSON。

四个 LeetCode 抓取工具,实时输入。leetcode-solution 拉取带代码块的单篇社区题解,leetcode-serp 读取题库,leetcode-problem 返回带题目描述和初始代码的单个题目,leetcode-solutions 读取题解标签页。切换标签,或悬停以暂停并阅读。

就绪
按键 1-4 切换 · 点击暂停运行你自己的 URL
几分钟内运行你的第一个请求。最多 20,000 次免费请求,无需信用卡。免费开始
02 功能

一个 API,覆盖 LeetCode 的每个角落。

四个专用抓取工具覆盖重要的页面:题库、单个题目、题解标签页和单篇题解。Crawling API 在真实浏览器中渲染每个页面,通过住宅 IP 访问,并交付干净的 HTML 或 JSON。

题库

完整的题目目录

leetcode-serp 将题库页面转换为 JSON:totalProblems 和 problemCount,外加每一行的 id、title、titleSlug、url、难度、通过率、会员标记和每日一题标记。

题目

题目描述与初始代码

leetcode-problem 返回单个题目,带有以 HTML 和纯文本两种形式呈现的题目描述、难度、分类、主题标签、提示、示例测试用例、LeetCode 提供的每种语言的初始代码片段、相似题目,以及其点赞、点踩和提交计数。

题解

题解标签页

leetcode-solutions 以 JSON 返回题解标签页,每个帖子都带有其 id、title、url、作者名称和用户名、发布日期、标签、投票、浏览和评论数。

题解文章

单篇题解

添加 scraper=leetcode-solution 即可返回单篇题解,带有其作者、发布日期、标签、互动计数、以 HTML 和纯文本两种形式呈现的正文,以及每个渲染出的代码块及其语言。

代理

1.4 亿住宅 IP

每个请求都会在 30 个地区轮换一个住宅 IP,并自动清除机器人检查。无需求解,无需维护。

一个令牌

一个 API 覆盖每个页面

Crawling API 适用于任意 URL,因此同一个令牌覆盖每个 LeetCode 题目和题解以及你抓取的其他一切。 查看实时演示.

03 输出

每个题目字段,都是干净的 JSON。

发送一个题目 URL 并附上 scraper=leetcode-problem 题目就会以类型化 JSON 返回,包含主题标签和初始代码。换成 leetcode-serpleetcode-solutionsleetcode-solution 即可获取题库和社区题解。

{ "url": "https://leetcode.com/problems/two-sum/", "id": "1", "title": "Two Sum", "titleSlug": "two-sum", "difficulty": "Easy", "category": "Algorithms", "isPremium": false, "description": "You are given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.", "descriptionHtml": "<p>You are given an array of integers <code>nums</code>&nbsp;and an integer <code>target</code>...", "hints": [ "A really brute force way would be to search for all possible pairs of numbers...", "..." ], "topicTags": [ { "name": "Array", "slug": "array" }, { "name": "Hash Table", "slug": "hash-table" } ], "exampleTestcases": [ "[2,7,11,15]\n9", "[3,2,4]\n6", "[3,3]\n6" ], "codeSnippets": [ { "language": "Python3", "languageSlug": "python3", "code": "class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:" } ], "likes": 69478, "dislikes": 2592, "commentCount": 3490, "acceptedCount": 22929319, "submissionCount": 39569455, "acceptanceRate": "57.9%", "similarQuestions": [ { "title": "3Sum", "titleSlug": "3sum", "difficulty": "Medium" } ], "officialSolution": { "available": true, "isFree": true, "hasVideo": true }, "solutionsUrl": "https://leetcode.com/problems/two-sum/solutions/" }

题目

url · string  id · string  title · string  titleSlug · string

题目描述

description · string  descriptionHtml · string  hints · array  exampleTestcases · array

主题与代码

topicTags[].name · string  topicTags[].slug · string  codeSnippets[].languageSlug · string  codeSnippets[].code · string

互动数据

likes · number  dislikes · number  submissionCount · number  acceptanceRate · string

相关题目

similarQuestions[] · array  officialSolution.available · boolean  officialSolution.hasVideo · boolean  solutionsUrl · string

04 工作原理

一个调用,从 URL 到数据。

每个 LeetCode 请求都走同一条路径。你发送一个 URL,我们运营其间的一切。

01

发送 URL

用你的令牌传入任意公开的 LeetCode URL:题库、题目、题解标签页或单篇题解。

02

轮换代理

从 30 个地区的 1.4 亿 IP 中,选取能干净访问站点的住宅 IP 和地区。

03

渲染页面

真实浏览器加载页面,使得题目表格、题目描述面板和题解正文在捕获前完成渲染。

04

清除反爬

站点的机器人检查和限流都会自动处理。无需求解,无需维护。

05

返回 HTML 或 JSON

返回完整渲染的 HTML,或在你添加 leetcode-serp、leetcode-problem、leetcode-solutions 或 leetcode-solution 时返回类型化 JSON。

05 使用场景

团队用 LeetCode 数据构建什么。

USE / 01目录

题库索引

逐页遍历题库,构建可搜索的索引,收录每个题目的 id、slug、难度、通过率和会员标记。

USE / 02训练

面试备考工具

提取题目描述、提示、示例测试用例和初始代码片段,为练习应用、间隔重复卡组和内部备考路线提供支持。

USE / 03基准

模型与智能体评估

将题目描述连同其示例测试用例和参考题解组装成分级基准集,用于评估代码生成模型。

USE / 04研究

题解与模式挖掘

收集题解标签页和单篇题解,了解社区实际收敛到哪些解法、语言和数据结构。

USE / 05排名

难度与热度跟踪

随时间跟踪通过率、点赞、点踩、提交数、投票和浏览数,看清哪些题目和题解正在走热。

USE / 06覆盖

任意 URL,一个 API

抓取题库、题目、题解标签页和单篇题解,外加你需要的任何其他站点。

06 须知

抓取 LeetCode 时需要了解的要点。

默认 HTML,按需 JSON

你会得到完整渲染的 HTML。添加 scraper=leetcode-serp、leetcode-problem、leetcode-solutions 或 leetcode-solution 获取已解析的 JSON,或自行解析 HTML。

每日一题是额外的一行

LeetCode 会把每日一题固定在表格上方,因此完整的一页返回的行数会比页面大小多一行。它是唯一将 isDailyQuestion 设为 true 的行,因此请按该标记过滤,而不是按位置过滤。

会员题目只返回元数据

会员题目会保留其标识字段、isPremium 和主题标签,但题目描述和各项计数位于付费墙之后,返回为空。在把空的 description 当作解析失败之前,请先检查 isPremium。

各项计数按显示形式返回

LeetCode 在页面上会缩写超过一千的数字,因此 11.9K 会被还原为 11900。该值带有页面的精度,而不是精确数字。

07 为何选择 Crawlbase

为大规模抓取 LeetCode 而生。

Crawling API 运行在同一张网络上,为超过 46,000 名付费客户和 70,000 名开发者提供服务。无需购买代理,无需运行浏览器,站点变更时也无需打补丁。

99%
平均请求成功率
140M
住宅 IP,另加 9800 万数据中心 IP
30
用于精确本地结果的地区数
20/s
默认每秒请求数,可按需提升

一个令牌,面向 Python、Node 和 Ruby 的官方 SDK,底层是 99.99% 可用性的网络。

08 常见问题

关于抓取 LeetCode 的问题。

用你的令牌将任意 LeetCode URL 发送到 Crawlbase Crawling API。Crawlbase 会轮换一个住宅代理,在真实浏览器中渲染页面,清除机器人检查,并返回完整渲染的 HTML。添加专用抓取工具(scraper=leetcode-serpleetcode-problemleetcode-solutionsleetcode-solution)即可改为获取结构化 JSON。
可以。默认情况下 Crawling API 返回渲染后的 HTML;添加专用抓取工具即可接收结构化 JSON:leetcode-serp 用于题库,leetcode-problem 用于单个题目,leetcode-solutions 用于题解标签页,leetcode-solution 用于单篇题解。
leetcode.com 上的题库和题目列表页面、单个题目页面、题目的题解标签页,以及单篇题解页面。同一个 API 也适用于任何其他站点。
Crawlbase 通过 30 个地区的轮换住宅 IP 路由每个请求,并自动清除机器人检查,因此访问保持稳定,站点更改配置时也无需维护。
leetcode-serp 返回题库页面,带有 totalProblems、problemCount 以及每个题目一行。leetcode-problem 返回单个题目,带有其题目描述、主题标签、提示、示例测试用例、初始代码片段和各项计数。leetcode-solutions 返回题解标签页,每个帖子带有作者、标签和互动计数。leetcode-solution 返回单篇题解,带有其正文和每个渲染出的代码块。
leetcode-solution 抓取工具返回 codeBlocks,每个都带有其语言和完整源代码,同时以 HTML 和纯文本两种形式返回题解正文。只会返回在所提供标记中渲染出的代码块;如果某个帖子在点击时才挂载额外的语言标签页,那么只会暴露随页面一同下发的那个代码块。
免费开始,最多 20,000 次请求且无需信用卡。付费套餐随用量扩展,同一个令牌在 Crawling API 和每个 Crawlbase 抓取工具中通用。

开始抓取 LeetCode。
省去代理和限流。

免费开始,最多 20,000 次请求。一个令牌用于 Crawling API 和每个抓取工具。