Do you want to download a book from litres.com/ru, but it doesn't have such an feature? There is a solution to. This repo has two kinds of scripts: the first downloads raw book material - pages as images, the second is dedicated to convert the raw material to one of formats: PDF, TIFF - for a single file, and other formats.
Script get_images.py is of the first kind, it downloads the raw material with Selenium and it can raise error (see ChromeDriver issue). Scripts of the second kind are two there:
create_pdf_by_fpdf2.py(alive successor of fpdf, learn more: https://py-pdf.github.io/fpdf2/History.html)create_pdf_by_pillow.py(fork of PIL) The first one only converts the book to PDF, the second can convert to PDF, and image formats: AVIF, BMP, GIF, PDF, TIFF, JPEG, PNG, and more (see https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html)
The repo has also config.py. You need to set up it, namely:
- fill up your
LOGINandPASSWORDof your LitRes account - put your
BOOK_ID(to know, go to the book webpage, open the LitRes reader, its page will have an URL likehttps://litres.com/static/or3/view/or.html?art_type=4&file=00000000, you need a value of thefileparameter, it's the book ID) - put the book
PAGES(to know, open the book with the LitRes reader, run DevTools (Ctrl+Shift+I, usually), pick the last page by the element selector/picker (Ctrl+Shift+C), in the Elements tab, you will find animgelement which has the parentdiv, it has anidattribute likeid="p_X", a number X + 1 isPAGES)
After that:
- run
get_images.pyto download the raw material - run
create_pdf_by_X.py(fpdf2 or pillow) to get a PDF or another format of the book
That's done!
(The following solution is for GNU/Linux)
If you get an error like selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114 Current browser version is... when get_images.py is running, try:
- Check your Chrome/Chromium version
- Go to https://googlechromelabs.github.io/chrome-for-testing/ or to https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
- Download a necessary version of ChromeDriver (not Chrome)
- Unzip the archive
- Find your ChromeDriver executable folder (something like
/usr/bin/chromedriver-linux64) - Move/copy the downloaded ChromeDriver to that folder, i.e. replace the existing one
- Try to run
get_images.pyagain