【问题标题】:Reading many pdf files in python在python中读取许多pdf文件
【发布时间】:2018-06-04 10:38:35
【问题描述】:

在一个目录中有一堆带有文本的 PDF 文件。我的想法是能够一次阅读它们并保存在字典中。现在我只能通过使用textract 库来一一完成:

import textract

text = textract.process('/Users/user/Documents/Data/CLAR.pdf', 
                        method='tesseract', 
                        language='eng')

如何一次阅读它们?我是否需要使用for 循环在目录或其他方式中搜索?

【问题讨论】:

    标签: python parsing pdf text


    【解决方案1】:

    一种解决方案可能是使用os libraryfor loop

    import os
    import textract
    
    files_path = [os.path.abspath(x) for x in os.listdir()]
    
    # Excluding not .pdf files
    files_path = [pdf for pdf in files_path if '.pdf' in pdf]
    
    pdfs = []
    for file in files_path:
        text = textract.process(file,
                                method='tesseract',
                                language='eng')
    
        pdfs += [text]
    
    1. 获取当前目录下的所有文件
    2. 不排除.pdf文件
    3. 将文本保存到列表中(可能是不同的数据结构)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-27
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 2017-11-12
      • 2011-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多