V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
soho176
V2EX  ›  Python

Python 读取 doc 文件有啥好办法那?注意是 doc,不是 docx.

  •  
  •   soho176 · May 21, 2018 · 6085 views
    This topic created in 2909 days ago, the information mentioned may be changed or developed.
    8 replies    2018-05-23 14:54:56 +08:00
    soho176
        1
    soho176  
    OP
       May 21, 2018
    找到了这个办法。
    antiword 是 linux 及其他 RISC OS 下免费的 ms word 文档读取器。使用它可以很方便的在 Linux 中读取 word 文档并输出为纯文本字符串。

    下载地址: http://www.winfield.demon.nl

    下载后解压、编译安装:

    tar -zxvf antiword-0.37.tar.gz
    cd antiword-0.37
    make
    make install
    默认安装到当前账户下的 bin 目录中。

    使用:
    终端中

    /home/pi/bin/antiword antiword-test.doc
    其他语言中通过各自执行系统命令的方式来执行,比如 Python 中:

    import subprocess
    word_file = "antiword-test.doc"
    content = subprocess.check_output(["/home/pi/antiword", word_file])
    print content
    soho176
        2
    soho176  
    OP
       May 21, 2018
    但是这个办法是 Linux 下的有没有 win 下的办法那?
    xuegj1010
        3
    xuegj1010  
       May 21, 2018
    先用 win32com 把 doc 转换成 docx,然后再用 python-docx 读 docx 就比较好处理了
    soho176
        4
    soho176  
    OP
       May 21, 2018
    @xuegj1010 这个办法我试过了,doc 转 docx 的时候电脑会打开 doc 文件,好像我这盗版的有啥文件缺失,没法转成功
    omph
        5
    omph  
       May 21, 2018
    PythonAnswer
        6
    PythonAnswer  
       May 21, 2018 via iPhone
    找台电脑转 docx
    Arnie97
        7
    Arnie97  
       May 23, 2018 via Android
    我非常确定 Antiword 支持 Windows,我在 Windows 下用它来实现 Word 文档的 git diff。
    soho176
        8
    soho176  
    OP
       May 23, 2018
    @Arnie97 确定能这样用?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3781 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 95ms · UTC 04:41 · PVG 12:41 · LAX 21:41 · JFK 00:41
    ♥ Do have faith in what you're doing.