Python - epub2txt


关于 epub2txt

Convert epub file to txt


安装

pip install epub2txt

命令行使用

查看 options

epub2txt --helpfull

输出较多,见文末


常见用法

# convert test.epub to test.txt
epub2txt -f test.epub

# browse for epub file, txt file will be in the same directory as the epub file
epub2txt

# show epub book info: title and toc
epub2txt -i

# show more epub book info: title, toc, metadata, spine (list of stuff packed into the epub)
epub2txt -m

# show epub2txt version
epub2txt -V

示例1

epub2txt -i

终端输入以下命令,系统将弹出文件夹,让用户选择 文件;然后产生结果如下:

晨间日记的奇迹(精排版)
[('封面', 'text00000.html'), 
('作者序', 'text00002.html'), 
('给所有台湾的心灵之友们', 'text00003.html'),
 ...
('参考文献', 'text00077.html'), 
('结\t语', 'text00078.html')]

Python 代码调用

from epub2txt import epub2txt
# 从网络 epub 转换
url = "https://github.com/ffreemt/tmx2epub/raw/master/tests/1.tmx.epub"
res = epub2txt(url)   # res 为字符串类型


# 从本地 epub 文件
filepath = r"tests\test.epub"
res = epub2txt(filepath)

# output as a list of chapters
ch_list = epub2txt(filepath, outputlist=True)  
# chapter titles will be available as epub2txt.content_titles if available
# 一个章节作为 输出list 的一个 item,效果如下

在这里插入图片描述


manual

epub2txt --helpfull

USAGE: /Users/xx/miniconda3/bin/epub2txt [flags]


flags:

absl.app:

  • -?,--[no]help: show this help
    (default: ‘false’)

  • --[no]helpfull: show full help
    (default: ‘false’)

  • --[no]helpshort: show this help
    (default: ‘false’)

  • --[no]helpxml: like --helpfull, but generates XML output
    (default: ‘false’)

  • --[no]only_check_args: Set to true to validate args and exit.
    (default: ‘false’)

  • --[no]pdb: Alias for --pdb_post_mortem.
    (default: ‘false’)

  • --[no]pdb_post_mortem: Set to true to handle uncaught exceptions with PDB post mortem.
    (default: ‘false’)

  • --profile_file: Dump profile information to a file (for python -m pstats). Implies --run_with_profiling.

  • --[no]run_with_pdb: Set to true for PDB debug mode
    (default: ‘false’)

  • --[no]run_with_profiling: Set to true for profiling the script. Execution will be slower, and the output format might change over time.
    (default: ‘false’)

  • --[no]use_cprofile_for_profiling: Use cProfile instead of the profile module for profiling. This has no effect unless --run_with_profiling is set.
    (default: ‘true’)


absl.logging:

  • --[no]alsologtostderr: also log to stderr?
    (default: ‘false’)
  • --log_dir: directory to write logfiles into
    (default: ‘’)
  • --logger_levels: Specify log level of loggers. The format is a CSV list of name:level. Where name is the logger name used with logging.getLogger(), and level is a level name (INFO, DEBUG, etc). e.g. myapp.foo:INFO,other.logger:DEBUG
    (default: ‘’)
  • --[no]logtostderr: Should only log to stderr?
    (default: ‘false’)
  • --[no]showprefixforinfo: If False, do not prepend prefix to info messages when it’s logged to stderr, --verbosity is set to INFO level, and python logging is used.
    (default: ‘true’)
  • --stderrthreshold: log messages at this level, or more severe, to stderr in addition to the logfile. Possible values are ‘debug’, ‘info’, ‘warning’, ‘error’, and ‘fatal’. Obsoletes --alsologtostderr. Using --alsologtostderr cancels the effect of this flag. Please also note that this flag is subject to --verbosity and requires logfile not be stderr.
    (default: ‘fatal’)
  • -v,--verbosity: Logging verbosity level. Messages logged at this level or lower will be included. Set to 1 for debug logging. If the flag was not set or supplied, the value will be changed from the default of -1 (warning) to 0 (info) after flags are parsed.
    (default: ‘-1’)
    (an integer)

epub2txt.main:

  • --[no]debug: print verbose debug messages
    (default: ‘false’)
  • -d,--dest: destintioin folder to save the epub file, if left empty, set to the same folder where tmx file is located
    (default: ‘’)
  • -m,--[no]detailed-info: print more detailed book info and exit
    (default: ‘false’)
  • -f,--filename: tmx filename (can be gzip or bz2)
    (default: ‘’)
  • -i,--[no]info: print book info and exit
    (default: ‘false’)
  • -V,--[no]version: print version and exit
    (default: ‘false’)

absl.flags:

  • --flagfile: Insert flag definitions from the given file into the command line.
    (default: ‘’)
  • --undefok: comma-separated list of flag names that it is okay to specify on the command line even if the program does not define a flag with that name. IMPORTANT`: flags in this list that have arguments MUST use the --flag=value format.
    (default: ‘’)

2024-03-24(日)

相关推荐

  1. Python编程入门EPUB:探索编程世界的奇幻之旅

    2024-03-27 15:20:02       7 阅读
  2. ROS2 CMakeLists.txt 和 package.xml

    2024-03-27 15:20:02       27 阅读
  3. python为当前项目生成requirements.txt

    2024-03-27 15:20:02       32 阅读
  4. python修改txt文件指定行内容

    2024-03-27 15:20:02       18 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-27 15:20:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-27 15:20:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-27 15:20:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-27 15:20:02       18 阅读

热门阅读

  1. ocs2安装

    2024-03-27 15:20:02       14 阅读
  2. LeetCode //C - 704. Binary Search

    2024-03-27 15:20:02       20 阅读
  3. 008-如何支持各种语言的项目

    2024-03-27 15:20:02       14 阅读
  4. unity中平台判断

    2024-03-27 15:20:02       14 阅读
  5. .NET Core教程:深入实践与实例解析

    2024-03-27 15:20:02       18 阅读
  6. Gartner发布2024年影响技术提供商的重大趋势

    2024-03-27 15:20:02       18 阅读
  7. Windows CMD命令大全(快速上手)

    2024-03-27 15:20:02       17 阅读
  8. 深入理解 C++ 中的 IO 流【iostream篇】

    2024-03-27 15:20:02       16 阅读
  9. Canathus 一个简单的React表单验证工具

    2024-03-27 15:20:02       15 阅读