V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-05-21 13:19:06 +08:00 · 5463 次点击
    这是一个创建于 2160 天前的主题,其中的信息可能已经有所发展或是发生改变。
    8 条回复    2018-05-23 14:54:56 +08:00
    soho176
        1
    soho176  
    OP
       2018-05-21 13:56:39 +08:00
    找到了这个办法。
    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
       2018-05-21 19:02:59 +08:00
    但是这个办法是 Linux 下的有没有 win 下的办法那?
    xuegj1010
        3
    xuegj1010  
       2018-05-21 21:24:39 +08:00
    先用 win32com 把 doc 转换成 docx,然后再用 python-docx 读 docx 就比较好处理了
    soho176
        4
    soho176  
    OP
       2018-05-21 21:38:55 +08:00
    @xuegj1010 这个办法我试过了,doc 转 docx 的时候电脑会打开 doc 文件,好像我这盗版的有啥文件缺失,没法转成功
    omph
        5
    omph  
       2018-05-21 22:02:12 +08:00
    PythonAnswer
        6
    PythonAnswer  
       2018-05-21 23:38:01 +08:00 via iPhone
    找台电脑转 docx
    Arnie97
        7
    Arnie97  
       2018-05-23 01:17:09 +08:00 via Android
    我非常确定 Antiword 支持 Windows,我在 Windows 下用它来实现 Word 文档的 git diff。
    soho176
        8
    soho176  
    OP
       2018-05-23 14:54:56 +08:00
    @Arnie97 确定能这样用?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1792 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:26 · PVG 00:26 · LAX 09:26 · JFK 12:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.