Skip to content

Scraper for automating the extraction of LeetCode problem descriptions and solutions.

Notifications You must be signed in to change notification settings

SaraSaadoun/Leetcode-Scraper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ LeetCode Scraper

Automate the process of saving your LeetCode solutions with ease! This scraper authenticates, extracts solutions, saves metadata, and commits automatically using Git.

πŸ”Ή Features

βœ… Authenticates on LeetCode
βœ… Scrapes code, language, runtime, memory, and problem description
βœ… Adjusts file extensions based on the detected programming language
βœ… Saves metadata (runtime & memory) in a JSON file
βœ… Stores problem descriptions in a Markdown file
βœ… Organizes everything in a directory named after the problem slug
βœ… Commits automatically using Git after scraping 🎯
βœ… Choose what to scrape β†’ Select all submissions or just the latest one! πŸ”„

πŸ“‚ Project Structure

│── LeetCodeSolutions/ 
│── src/ β”‚ 
β”œβ”€β”€ controllers/ 
β”‚ β”‚ β”œβ”€β”€ file_controller.py 
β”‚ β”‚ β”œβ”€β”€ git_controller.py 
β”‚ β”œβ”€β”€ scrapers/ 
β”‚ β”‚ β”œβ”€β”€ scraper.py 
β”‚ β”œβ”€β”€ utils/ 
β”‚ β”‚ β”œβ”€β”€ config.py
β”‚ β”œβ”€β”€ auth.py 
β”‚ β”œβ”€β”€ main_ui.py 
β”‚ β”œβ”€β”€ main.py 
│── .gitignore 
│── README.md 
│── requirements.txt

πŸ› οΈ Installation

git clone https://github.com/SaraSaadoun/Leetcode-Scraper.git  
cd Leetcode-Scraper  
pip install -r requirements.txt

πŸ”Ή Setup .env File

Before running the script, create a .env file in the project directory and define the absolute path where you want to save the scraped solutions:

LEETCODE_SOLUTIONS_DIR_PATH=/absolute/path/to/save/solutions

πŸš€ Running the Scraper

cd src
python auth.py
python main.py --slug problem-slug-here

πŸ”Ή Usage Notes

  • The --slug argument accepts both problem slugs (e.g., two-sum) and problem names (e.g., "Two Sum").
  • If you want to scrape all accepted solutions instead of just the latest one, pass the --all_submissions flag:
python main.py --slug problem-slug-here --all_submissions

πŸ–₯️ Running with UI

For a simpler experience, you can run the scraper with a graphical user interface:

python main_ui.py

This will allow you to input the problem name/slug and choose options interactively.

About

Scraper for automating the extraction of LeetCode problem descriptions and solutions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages