我正在使用Python脚本将一个file.doc文件转换成file.txt文件。我的代码如下:
from subprocess import Popen, PIPE
from docx import opendocx, getdocumenttext
#https://dev59.com/fW025IYBdhLWcg3w6aUX
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO import StringIO
import os
def document_to_text(filename, file_path):
if filename[-4:] == ".doc":
cmd = ['antiword', file_path]
p = Popen(cmd, stdout=PIPE)
stdout, stderr = p.communicate()
return stdout.decode('ascii', 'ignore')
elif filename[-5:] == ".docx":
document = opendocx(file_path)
paratextlist = getdocumenttext(document)
newparatextlist = []
for paratext in paratextlist:
newparatextlist.append(paratext.encode("utf-8"))
return '\n\n'.join(newparatextlist)
为了使用上面的脚本,我需要安装'antiword',但问题是我不知道如何做。 这里是下载'antiword'的链接:http://www-stud.rbi.informatik.uni-frankfurt.de/~markus/antiword/ 有人能帮忙吗?