Python - 读取 mobi 电子书内容


相关库:


使用 mobi-reader 库

安装

pip install mobi-reader

使用

from mobi import Mobi

file_path = "/Users/user/Downloads/萬曆十五年.mobi"
reader = Mobi(file_path)
output = reader.read()  # bytearray containing the decoded mobi file

reader.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.ncx

3 directories, 5 files

mobiunpack 命令行工具

$ mobiunpack --help
KindleUnpack v0.82
   Based 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 modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, version 3.
option --help not recognized

Description:
  Unpacks an unencrypted Kindle/MobiPocket ebook to html and images
  or an unencrypted Kindle/Print Replica ebook to PDF and images
  into 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(四)

相关推荐

  1. Python - 读取 mobi 电子内容

    2024-06-13 11:40:03       7 阅读
  2. Python - 处理电子的库

    2024-06-13 11:40:03       10 阅读
  3. KindleUnpack - Python解压Amazon / Kindlegen生成的电子

    2024-06-13 11:40:03       5 阅读
  4. Python 读取电子发票PDF 转成Excel

    2024-06-13 11:40:03       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-13 11:40:03       14 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-13 11:40:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-13 11:40:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-13 11:40:03       18 阅读

热门阅读

  1. C# list 成员对象是int型存在堆区还是栈区

    2024-06-13 11:40:03       7 阅读
  2. 数码管的位码和断码

    2024-06-13 11:40:03       6 阅读
  3. RushJs遇到Browserslist: caniuse-lite is outdated解决方案

    2024-06-13 11:40:03       6 阅读
  4. CopyOnWriteArrayList 详细讲解以及示范

    2024-06-13 11:40:03       6 阅读
  5. 服务器时区与数据库时区不一致导致时间bug记录

    2024-06-13 11:40:03       4 阅读
  6. 安卓编程与iOS编程语言:深入比较与探索

    2024-06-13 11:40:03       7 阅读
  7. Android 列表视频滑动自动播放(实现思路)

    2024-06-13 11:40:03       7 阅读
  8. VSTO Word.net 如何在另外的工程内添加CustomTaskPane

    2024-06-13 11:40:03       4 阅读
  9. A. Problem Generator

    2024-06-13 11:40:03       5 阅读