Python Forum
Free e-books from Springer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Free e-books from Springer
#2
I saw it in the German forum: https://www.python-forum.de/viewtopic.php?f=21&t=48163

This should download all pdfs.
requests, bs4 and xlrd are required
have fun

import sys
from pathlib import Path

import xlrd
import requests
from bs4 import BeautifulSoup


URLS = {
    "Free Emergency Nursing titles (German)": "https://resource-cms.springernature.com/springer-cms/rest/v1/content/17856246/data/v3",
    "Free English textbook titles (all disciplines)": "https://resource-cms.springernature.com/springer-cms/rest/v1/content/17858272/data/v4",
    "Free German textbook titles (all disciplines)": "https://resource-cms.springernature.com/springer-cms/rest/v1/content/17863240/data/v2",
}
DOWNLOAD_PATH = Path("Download")
DOWNLOAD_PATH.mkdir(exist_ok=True)


def get_urls():
    sheets = []
    for kind, url in URLS.items():
        print("Downloading", kind)
        rep = requests.get(url)
        sheets.append(xlrd.open_workbook(file_contents=rep.content).sheet_by_index(0))

    result = []
    for sheet in sheets:
        iterator = zip(sheet.col_slice(0), sheet.col_slice(18))
        next(iterator)
        for title, url in iterator:
            result.append((title.value, url.value))
    return result


def get_downloads(pages):
    base = "https://link.springer.com"
    for title, url in pages:
        bs = BeautifulSoup(requests.get(url).content, "html.parser")
        if result := bs.find("a", href=True, attrs={"class": "c-button"}):
            yield title, base + result.get("href")


def downloader(title, url):
    _, _, suffix = url.rpartition(".")
    target = (DOWNLOAD_PATH / title).with_suffix("." + suffix)
    if not target.exists():
        print(f"Downloading `{title}`")
        with target.open("wb") as fd:
            rep = requests.get(url, stream=True)
            for chunk in rep.iter_content(8196):
                fd.write(chunk)


def download():
    links_to_books = get_urls()
    print(f"Downloading {len(links_to_books)} eBooks")
    for title, url in get_downloads(links_to_books):
        try:
            downloader(title, url)
        except Exception as e:
            print(e, file=sys.stderr)


if __name__ == "__main__":
    download()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Free e-books from Springer - by perfringo - Apr-29-2020, 10:26 AM
RE: Free e-books from Springer - by DeaD_EyE - Apr-29-2020, 02:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  books on learning coding alok 3 2,700 Aug-22-2022, 03:17 PM
Last Post: Larz60+
  Best books for programming katy1234 0 1,425 May-26-2022, 12:47 PM
Last Post: katy1234
  Python Books - Recommendation lasek723 5 3,862 Oct-29-2020, 08:01 AM
Last Post: snippsat
  Python books for beginners BillMcEnaney 1 2,106 Sep-10-2020, 06:57 AM
Last Post: Gribouillis
  python books koby 3 2,655 Jan-21-2020, 02:29 PM
Last Post: perfringo
  All Apress & Springer IT eBooks only 7€ buran 0 1,650 Nov-27-2019, 04:44 PM
Last Post: buran
  [book] Various python and non python books available each day (free for 24hrs) Yoriz 188 124,456 Aug-09-2019, 04:57 AM
Last Post: ThomasL
  Python Books SZaretsky 3 49,410 Apr-30-2018, 12:40 PM
Last Post: SZaretsky
  Free Programming Notes for Professionals Books buran 2 4,285 Jan-16-2018, 12:34 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020