我试图从一些docx文件中提取大量的文本并将它们存储在.txt文件中。在
我使用的语言是波斯语/阿拉伯语(它们是从右到左的语言),所以我很难使用pythondocx。我无法以适当的形式提取文本,它们都被混合在.txt文件中。在
提取形式=https://pasteboard.co/Id8jj7g.jpg
原始形式=https://pasteboard.co/Id8jv1i.jpg
import docx
doc = docx.Document('1.docx')
text_file = open('data.txt','w', encoding='utf8')
print(len(doc.paragraphs))
for txt in doc.paragraphs:
text_file.write(txt.text+'\n')
我需要先把形式定义得合适。如果你正在做一个NLP项目,你需要有句子和句子中的每个单词。我认为下面的代码对于从docx文件中提取文本很有帮助。(Python 2.7)
有关详细信息,请阅读docxpy文档: docxpy website
相关问题 更多 >
编程相关推荐