我正在做一个项目,我需要从多个doc和docx文件中读取文本。docx文件很容易用docx2txt模块完成,但我无法让它对doc文件起作用。我试过用textract,但似乎在Windows上行不通。我只需要文件中的文本,不需要图片或类似的东西。有什么好办法吗?
我发现,这似乎是工作。
import win32com.client
text = win32com.client.Dispatch("Word.Application")
text.visible = False
wb = text.Documents.Open("myfile.doc")
document = text.ActiveDocument
print(document.Range().Text)