LeetCode Problem Set
Parsen Sie eine LeetCode-Aufgabenliste in strukturiertes JSON mit Aufgaben-ID, Titel, Schwierigkeit, Erfolgsquote, Premium-Kennzeichen und URL.
LeetCode heftet die tägliche Challenge über die paginierte Tabelle, daher liefert eine volle Seite einen Eintrag mehr als die Seitengröße - zuerst die angeheftete Aufgabe, dann die Tabellenzeilen. Sie ist der einzige Eintrag mit isDailyQuestion auf true, lässt sich also einfach entfernen, wenn Sie nur die Tabelle möchten.
API-Nutzung
Fügen Sie &scraper=leetcode-serp zu einem Crawling-API-Request hinzu. Kodieren Sie die Ziel-URL im Parameter url URL-encoded.
curl 'https://api.crawlbase.com/?token=YOUR_TOKEN' \
--data-urlencode 'url=https://leetcode.com/problemset/' \
--data-urlencode 'scraper=leetcode-serp' -Gfrom crawlbase import CrawlingAPI
api = CrawlingAPI({'token': 'YOUR_TOKEN'})
res = api.get(
'https://leetcode.com/problemset/',
{'scraper': 'leetcode-serp'}
)
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/problemset/',
{ scraper: 'leetcode-serp' }
);
const data = JSON.parse(res.body);require 'crawlbase'
api = Crawlbase::API.new(token: 'YOUR_TOKEN')
res = api.get('https://leetcode.com/problemset/', scraper: 'leetcode-serp')
data = JSON.parse(res.body)Beispiel-Eingabe-URL
Im Parameter url funktioniert jede LeetCode-Aufgabenliste - die ungefilterte Liste unter /problemset/ oder eine gefilterte Ansicht. Zum Beispiel:
https://leetcode.com/problemset/
https://leetcode.com/problemset/?difficulty=EASY
https://leetcode.com/problemset/?topicSlugs=dynamic-programmingResponse-Struktur
JSON-Response-Body. Feldtypen können null sein, wenn die Quellseite den Wert nicht enthält.
problems zurückgegeben werden.Easy, Medium oder Hard.Beispiel-Response
{
"url": "https://leetcode.com/problemset/",
"totalProblems": 4013,
"problemCount": 101,
"problems": [
{
"id": "3626",
"title": "Smallest Divisible Digit Product I",
"titleSlug": "smallest-divisible-digit-product-i",
"url": "https://leetcode.com/problems/smallest-divisible-digit-product-i",
"difficulty": "Easy",
"acceptanceRate": "71.0%",
"isPremium": false,
"isDailyQuestion": true
},
{
"id": "1",
"title": "Two Sum",
"titleSlug": "two-sum",
"url": "https://leetcode.com/problems/two-sum",
"difficulty": "Easy",
"acceptanceRate": "57.9%",
"isPremium": false,
"isDailyQuestion": false
},
{
"id": "2",
"title": "Add Two Numbers",
"titleSlug": "add-two-numbers",
"url": "https://leetcode.com/problems/add-two-numbers",
"difficulty": "Medium",
"acceptanceRate": "49.1%",
"isPremium": false,
"isDailyQuestion": false
}
]
}