本文主要是介绍Python - 读取 mobi 电子书内容,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 使用 mobi-reader 库
- 安装
- 使用
- 使用 mobi 库
- 安装
- 读取
- 查看文件
- mobiunpack 命令行工具
相关库:
- mobi : https://github.com/iscc/mobi
- mobi-reader : https://github.com/MrLucio/mobi-reader
使用 mobi-reader 库
安装
pip install mobi-reader
使用
from mobi import Mobifile_path = "/Users/user/Downloads/萬曆十五年.mobi"
reader = Mobi(file_path)
output = reader.read() # bytearray containing the decoded mobi filereader.close()type(output) # -> <class 'bytearray'>
content = output.decode('utf-8')
content 内容很长,可以保存到文件夹,不要轻易在终端打印
使用 mobi 库
安装
pip install mobi
读取
from mobi import Mobi
tempdir, filepath = mobi.extract("/Users/user/Downloads/萬曆十五年.mobi")
# tempdir, filepath --> ('/var/folders/3n/j60lmmv93kngjr3cv_00zmvr0000gn/T/mobiexejtyu2zc', '/var/folders/3n/j60lmmv93kngjr3cv_00zmvr0000gn/T/mobiexejtyu2zc/mobi7/book.html')
内容将保存在指定文件夹
查看文件
$ cd '/var/folders/3n/j60lmmv93kngjr3cv_00zmvr0000gn/T/mobiexejtyu2zc'
$ tree
.
├── HDImages
└── mobi7├── Images│ ├── cover00137.jpeg│ └── image00138.jpeg├── book.html├── content.opf└── toc.ncx3 directories, 5 files
mobiunpack 命令行工具
$ mobiunpack --help
KindleUnpack v0.82Based on initial mobipocket version Copyright © 2009 Charles M. Hannum <root@ihack.net>Extensive Extensions and Improvements Copyright © 2009-2014 by: P. Durrant, K. Hendricks, S. Siebert, fandrieu, DiapDealer, nickredding, tkeo.This program is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, version 3.
option --help not recognizedDescription:Unpacks an unencrypted Kindle/MobiPocket ebook to html and imagesor an unencrypted Kindle/Print Replica ebook to PDF and imagesinto the specified output folder.
Usage:mobiunpack -r -s -p apnxfile -d -h --epub_version= infile [outdir]
Options:-h print this help message-i use HD Images, if present, to overwrite reduced resolution images-s split combination mobis into mobi7 and mobi8 ebooks-p APNXFILE path to an .apnx file associated with the azw3 input (optional)--epub_version= specify epub version to unpack to: 2, 3, A (for automatic) or F (force to fit to epub2 definitions), default is 2-d dump headers and other info to output and extra files-r write raw data to the output folder
2024-06-06(四)
这篇关于Python - 读取 mobi 电子书内容的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!