Coder Social home page Coder Social logo

bishalsarang / leetcode-questions-scraper Goto Github PK

View Code? Open in Web Editor NEW
132.0 3.0 39.0 18.4 MB

Scrape Algorithm Questions from leetcode and generate html and epub file

Home Page: https://bishalsarang.github.io/Leetcode-Questions/out.html

Python 100.00%
scrapper leetcode leetcode-downloader leetcode-offline leetcode-epub leetcode-pdf leetcode-questions leetcode-scrapper leetcode-download leetcode-problems-solutions

leetcode-questions-scraper's Introduction

Leetcode Questions Scraper

Note: If you want to download daily updated problems you can visit my repo Leetcode Questions which basically checks leetcode daily and dowloads new problems if available. Here is the preview link for latest html https://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 url https://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
enter image description here
We can build links to each problem as

“https://leetcode.com/problems/" + question_title_slug

After 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 problems here.

Requirements

I have tested it on windows machine running with Google Chrome 77.0.3865.75 and chrome driver from here 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 to CHROMEDRIVER_PATH inside main.py

Pip install all the requirements.

requests==2.22.0
beautifulsoup4==4.8.0
selenium==3.141.0
EbookLib==0.17.1
colorama==0.4.1

How to use

  • 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.py enter image description here This downloads problem contents to 2 files: out.html and chapters.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 to track.conf file, the download resumes from where it failed.

Here is how sample out.html looks like. Sample out.html

After main.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 enter image description here

Here is how sample epub file looks like Sample

You can download sample files from here which contains 11 problem.

  1. Sample Out.epub
  2. Sample Out.html

Support

If you like this project and want to support it, consider buying me a coffee!

Buy Me A Coffee

Thank you for your support!

leetcode-questions-scraper's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

leetcode-questions-scraper's Issues

Feature: Updating the backend system to rely on GraphQL API instead of Web Scraping

Description

This Issue is more like a suggestion that might make this project more awesome.

I have been working on a similar project and, I have noticed that you are relying on web scraping instead of using the Leetcode GraphQL API. Using an API will boost the speed of your backend process when compared to web scraping.

Feel free to close the issue👍🏼.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.