欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > Python - 读取 mobi 电子书内容

Python - 读取 mobi 电子书内容

2025/2/24 13:26:15 来源:https://blog.csdn.net/lovechris00/article/details/139507296  浏览:    关键词: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(四)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词