Leetcode Scrapper
LeetCode Scraper is a Selenium based Python script that scrapes information from Leetcode.com and stores the data in JSON format.
Note: if you just want to see company wise problems check out the subtree here , it is scraped in Febuary 2023. Alternatively you can checkout Leetcode Premium Unlocker browser extension, which will automatically inject premium data when you open the website.
Dependencies
selenium==4.8.0
Currently Supported pages
https://leetcode.com/problemset/*
https://leetcode.com/problem-list/*
https://leetcode.com/company/
Usage
clone repo + install dependencies
git clone https://github.com/Edwardsoen/LeetcodeScrapper.git
cd LeetcodeScrapper
pip install -r requirements.txt
download chromedriver here and paste it to system path
if you want to scrape single page, simply run
Python3 main.py {url}
but in most cases you probably want to scrape multiple pages, in which case you need to store the urls into seperate txt file (or you can use pre-scrapped urls here) and pass it like this
Python3 main.py {urlsfile.txt}
if you need to scrape premium data you can pass username and password like so
Python3 main.py -u {username} -p {password} {urls}
Sample output
Company Problem page
```
{
"data": [
{
"duration": "All time",
"problemData": [
{
"acceptance": "73.6%",
"difficulty": "Medium",
"frequency": 0,
"problemId": "2020",
"problemName": "Number of Accounts That Did Not Stream",
"url": "https://leetcode.com/problems/number-of-accounts-that-did-not-stream"
}
]
},
{
"duration": "All time",
"problemData": [
{
"acceptance": "52.0%",
"difficulty": "Medium",
"frequency": 0,
"problemId": "1990",
"problemName": "Count the Number of Experiments",
"url": "https://leetcode.com/problems/count-the-number-of-experiments"
}
]
},
{
"duration": "All time",
"problemData": [
{
"acceptance": "72.7%",
"difficulty": "Medium",
"frequency": 0,
"problemId": "1951",
"problemName": "All the Pairs With the Maximum Number of Common Followers",
"url": "https://leetcode.com/problems/all-the-pairs-with-the-maximum-number-of-common-followers"
}
]
}
],
"companyName": [
"instagram"
]
}
```
Front page
```
{
"tableData": [
{
"isPremium": false,
"problemName": "2551. Put Marbles in Bags",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "51.5%",
"difficulty": "Hard",
"frequency": "10.7001%",
"url": "https://leetcode.com/problems/put-marbles-in-bags/"
},
{
"isPremium": false,
"problemName": "2552. Count Increasing Quadruplets",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "31.5%",
"difficulty": "Hard",
"frequency": "7.09464%",
"url": "https://leetcode.com/problems/count-increasing-quadruplets/"
},
{
"isPremium": false,
"problemName": "2553. Separate the Digits in an Array",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "78.1%",
"difficulty": "Easy",
"frequency": "0%",
"url": "https://leetcode.com/problems/separate-the-digits-in-an-array/"
},
{
"isPremium": false,
"problemName": "2554. Maximum Number of Integers to Choose From a Range I",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "50.3%",
"difficulty": "Medium",
"frequency": "0%",
"url": "https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i/"
},
{
"isPremium": false,
"problemName": "2555. Maximize Win From Two Segments",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "22.8%",
"difficulty": "Medium",
"frequency": "0.166546%",
"url": "https://leetcode.com/problems/maximize-win-from-two-segments/"
},
{
"isPremium": false,
"problemName": "2556. Disconnect Path in a Binary Matrix by at Most One Flip",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "21.5%",
"difficulty": "Medium",
"frequency": "0%",
"url": "https://leetcode.com/problems/disconnect-path-in-a-binary-matrix-by-at-most-one-flip/"
},
{
"isPremium": false,
"problemName": "2557. Maximum Number of Integers to Choose From a Range II",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "49.4%",
"difficulty": "Medium",
"frequency": "0%",
"url": "https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-ii/"
},
{
"isPremium": false,
"problemName": "2558. Take Gifts From the Richest Pile",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "63.6%",
"difficulty": "Easy",
"frequency": "0%",
"url": "https://leetcode.com/problems/take-gifts-from-the-richest-pile/"
},
{
"isPremium": false,
"problemName": "2559. Count Vowel Strings in Ranges",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "47.9%",
"difficulty": "Medium",
"frequency": "0%",
"url": "https://leetcode.com/problems/count-vowel-strings-in-ranges/"
},
{
"isPremium": false,
"problemName": "2560. House Robber IV",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "27.1%",
"difficulty": "Medium",
"frequency": "0%",
"url": "https://leetcode.com/problems/house-robber-iv/"
},
{
"isPremium": false,
"problemName": "2561. Rearranging Fruits",
"haveSolution": false,
"isVideoSolution": false,
"acceptance": "25.6%",
"difficulty": "Hard",
"frequency": "0%",
"url": "https://leetcode.com/problems/rearranging-fruits/"
}
],
"page": "52"
}
```
Problem page
```
{
"tags": [
{
"duration": "1 year - 2 years",
"companies": [
[
"1 year - 2 years",
"Amazon"
]
]
}
],
"problem": "
You are given a 0-indexed integer array nums
and a positive integer k
.
\n\n
We call an index i
k-big if the following conditions are satisfied:
\n\n
\n\t- There exist at least
k
different indices idx1
such that idx1 < i
and nums[idx1] < nums[i]
. \n\t- There exist at least
k
different indices idx2
such that idx2 > i
and nums[idx2] < nums[i]
. \n
\n\n
Return the number of k-big indices.
\n\n
\n
Example 1:
\n\n
Input: nums = [2,3,6,5,2,3], k = 2\nOutput: 2\nExplanation: There are only two 2-big indices in nums:\n- i = 2 --> There are two valid idx1: 0 and 1. There are three valid idx2: 2, 3, and 4.\n- i = 3 --> There are two valid idx1: 0 and 1. There are two valid idx2: 3 and 4.\n
\n\n
Example 2:
\n\n
Input: nums = [1,1,1], k = 3\nOutput: 0\nExplanation: There are no 3-big indices in nums.\n
\n\n
\n
Constraints:
\n\n
\n\t1 <= nums.length <= 105
\n\t1 <= nums[i], k <= nums.length
\n
\n",
"relatedTopics": [
"Array",
"Binary Search",
"Divide and Conquer",
"Binary Indexed Tree",
"Segment Tree",
"Merge Sort",
"Ordered Set"
],
"similarQuestions": [
{
"questionName": "Count of Smaller Numbers After Self",
"difficulty": "Hard"
},
{
"questionName": "Find All Good Indices",
"difficulty": "Medium"
}
],
"problemName": "count-the-number-of-k-big-indices"
}
```
Contributions
If you have premium account and want to 'donate' data, feel free to open merge request (remember to force add the output folder, it is git-ignored by default).