从Safari Books Online图书馆下载并生成您最喜欢的书籍的EPUB 。
我不对该程序的使用负责,这仅用于个人和教育目的。
在任何使用之前,请阅读O'Reilly的服务条款。
safaribooks
登录不再有效。cookies.json
中,见下文和问题。爱❤️) --kindle
选项首先,它需要安装python3
和pip3
或pipenv
。
$ git clone https://github.com/lorenzodifuccia/safaribooks.git
Cloning into ' safaribooks ' ...
$ cd safaribooks/
$ pip3 install -r requirements.txt
OR
$ pipenv install && pipenv shell
该程序仅依赖于两个Python 3模块:
lxml >= 4.1 . 1
requests >= 2.20 . 0
使用起来非常简单,只需从图书馆中选择一本书并替换为以下命令即可:
email:password
为您自己的。 $ python3 safaribooks.py --cred " [email protected]:password01 " XXXXXXXXXXXXX
ID 是您在图书描述页面的 URL 中找到的数字:
https://www.safaribooksonline.com/library/view/book-name/XXXXXXXXXXXXX/
像: https://www.safaribooksonline.com/library/view/test-driven-development-with/9781491958698/
$ python3 safaribooks.py --help
usage: safaribooks.py [--cred < EMAIL:PASS > | --login] [--no-cookies]
[--kindle] [--preserve-log] [--help]
< BOOK ID >
Download and generate an EPUB of your favorite books from Safari Books Online.
positional arguments:
< BOOK ID > Book digits ID that you want to download. You can find
it in the URL (X-es):
` https://learning.oreilly.com/library/view/book-
name/XXXXXXXXXXXXX/ `
optional arguments:
--cred < EMAIL:PASS > Credentials used to perform the auth login on Safari
Books Online. Es. ` --cred
" [email protected]:password01 " ` .
--login Prompt for credentials used to perform the auth login
on Safari Books Online.
--no-cookies Prevent your session data to be saved into
` cookies.json ` file.
--kindle Add some CSS rules that block overflow on ` table ` and
` pre ` elements. Use this option if you ' re going to
export the EPUB to E-Readers like Amazon Kindle.
--preserve-log Leave the `info_XXXXXXXXXXXXX.log` file even if there
isn ' t any error.
--help Show this help message.
第一次使用该程序时,您必须指定您的 Safari Books Online 帐户凭据(请here
查找特殊字符)。
下次您下载书籍时,在会话过期之前,您可以省略凭据,因为程序会将您的会话 cookie 保存在名为cookies.json
的文件中。
对于SSO ,请使用sso_cookies.py
程序,以便根据浏览器会话检索的 SSO cookie 创建cookies.json
文件(请按照these steps
操作)。
如果您使用共享电脑,请注意,因为有权访问您文件的每个人都可以窃取您的会话。如果您不想缓存 cookie,只需使用--no-cookies
选项,并通过--cred
选项或更安全的--login
选项始终提供您的凭据:这将在脚本过程中提示您输入凭据执行。
您可以通过在系统上设置环境变量HTTPS_PROXY
或在脚本中使用USE_PROXY
指令来配置代理。
重要提示:由于该脚本仅下载 HTML 页面并创建原始 EPUB,因此许多 CSS 和 XML/HTML 指令对于电子阅读器来说都是错误的。为了确保最佳的输出质量,我建议您始终使用 Calibre 将脚本获得的EPUB
转换为标准EPUB
。您还可以将 Calibre 的命令行版本与ebook-convert
结合使用,例如:
$ ebook-convert " XXXX/safaribooks/Books/Test-Driven Development with Python 2nd Edition (9781491958698)/9781491958698.epub " " XXXX/safaribooks/Books/Test-Driven Development with Python 2nd Edition (9781491958698)/9781491958698_CLEAR.epub "
执行后,您可以在每个电子阅读器中阅读9781491958698_CLEAR.epub
,并删除所有其他文件。
该程序还提供了一个选项,以确保想要将EPUB
导出到 Amazon Kindle 等电子阅读器的用户的最佳兼容性: --kindle
,它会阻止table
和pre
元素上的溢出(请参阅示例)。
在这种情况下,我建议您使用 Calibre 将EPUB
转换为AZW3
或MOBI
,请记住在这种情况下在转换选项中选择Ignore margins
:
$ python3 safaribooks.py --cred " [email protected]:MyPassword1! " 9781491958698
____ ___ _
/ __/__ _/ _/__ _____(_)
_ / _ ` / _/ _ ` / __/ /
/___/ _ ,_/_/ _ ,_/_/ /_/
/ _ )___ ___ / /__ ___
/ _ / _ / _ / ' _/(_-<
/____/___/___/_/_/___/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[-] Logging into Safari Books Online...
[*] Retrieving book info...
[-] Title: Test-Driven Development with Python, 2nd Edition
[-] Authors: Harry J.W. Percival
[-] Identifier: 9781491958698
[-] ISBN: 9781491958704
[-] Publishers: O ' Reilly Media, Inc.
[-] Rights: Copyright © O ' Reilly Media, Inc.
[-] Description: By taking you through the development of a real web application
from beginning to end, the second edition of this hands-on guide demonstrates the
practical advantages of test-driven development (TDD) with Python. You’ll learn
how to write and run tests before building each part of your app, and then develop
the minimum amount of code required to pass those tests. The result? Clean code
that works.In the process, you’ll learn the basics of Django, Selenium, Git,
jQuery, and Mock, along with curre...
[-] Release Date: 2017-08-18
[-] URL: https://learning.oreilly.com/library/view/test-driven-development-with/9781491958698/
[*] Retrieving book chapters...
[*] Output directory:
/XXXX/safaribooks/Books/Test-Driven Development with Python 2nd Edition (9781491958698)
[-] Downloading book contents... (53 chapters)
[#####################################################################] 100%
[-] Downloading book CSSs... (2 files)
[#####################################################################] 100%
[-] Downloading book images... (142 files)
[#####################################################################] 100%
[-] Creating EPUB file...
[*] Done: /XXXX/safaribooks/Books/Test-Driven Development with Python 2nd Edition
(9781491958698)/9781491958698.epub
If you like it, please * this project on GitHub to make it known:
https://github.com/lorenzodifuccia/safaribooks
e don ' t forget to renew your Safari Books Online subscription:
https://learning.oreilly.com
[ ! ] Bye !!
结果将是(使用 Calibre 打开EPUB
文件):
--kindle
选项: $ python3 safaribooks.py --kindle 9781491958698
右边是使用--kindle
选项创建的书,左边没有(默认):
对于任何类型的问题,请随时在GitHub上提出问题。
洛伦佐·迪·富西亚