- Notifications
You must be signed in to change notification settings - Fork47
Scrape Algorithm Questions from leetcode and generate html and epub file
Bishalsarang/Leetcode-Questions-Scraper
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Note: If you want to download daily updated problems you can visit my repoLeetcode Questions which basically checks leetcode daily and dowloads new problems if available. Here is the preview link for latest htmlhttps://bishalsarang.github.io/Leetcode-Questions/out.html
Leetcode Questions Scraper is a simple scrapper built on top of Selenium that fetches all the problems from leetcode and write as html and epub files.
Although leetcode doesn't provide an official API to fetch all the list of problems, we can use the API urlhttps://leetcode.com/api/problems/algorithms/ used by leetcode internally to fetch problems that returns a json file containing info about problems.The json file looks like this
We can build links to each problem as
“https://leetcode.com/problems/" + question_title_slugAfter getting the problem link we can fetch the content from the page using selenium (as Leetcode is built using react where content is rendered using JS we can't use lightweight library like requests).
You can download the sample html and epub containing 11 problemshere.
I have tested it on windows machine running with Google Chrome 77.0.3865.75 and chrome driver fromhere and put it inside driver directory.I haven't tested with Linux and Mac but you can download chrome driver for respective platform and make change toCHROMEDRIVER_PATH insidemain.py
Pip install all the requirements.
requests==2.22.0beautifulsoup4==4.8.0selenium==3.141.0EbookLib==0.17.1colorama==0.4.1- Clone the repo and install all the dependencies including latest google chrome and latest chrome driver
- Update chrome driver path
- Run the following commands to download all algorithmic problems from leetcode
python main.pyThis downloads problem contents to 2 files:out.html andchapters.pickle.
NOTE: Leetcode may temporarily block requests. If the error occurs, wait for sometime and try again or use the proxy. Don't worry, Since, the previous state is saved totrack.conf file, the download resumes from where it failed.
Here is how sampleout.html looks like.
Aftermain.py script executes successfully. The pickle file is automatically converted to "Leetcode Questions.epub".
But you can also convert manually to epub with existing downloaded content with.python epub_writer.py
Here is how sample epub file looks like
You can download sample files from here which contains 11 problem.
If you like this project and want to support it, consider buying me a coffee!
Thank you for your support!
About
Scrape Algorithm Questions from leetcode and generate html and epub file
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
