【问题标题】:How to extract all the lines with keywords from pdf files in python?如何从python中的pdf文件中提取所有带有关键字的行?
【发布时间】:2022-12-12 06:31:01
【问题描述】:

我有多个 pdf 链接,我必须从中提取所有带有作者姓名的行。但有时作者太多,写成多行,或一行写名,下一行写姓氏。这给我带来了一个问题,我无法有效地提取所有这些行。

    authors = ['Francesca Donato', 'Marisa Matias', Ignazio Corrao', and so on....]
    line_number = 0
    list_of_results = []
    # Open the file in read only mode
    with open('file.txt', 'r') as read_obj:
        # Read all lines in the file one by one
        for line in read_obj:
            line_number += 1
            # For each line, check if line contains any string from the list of strings
            for string_to_search in authors:
                if string_to_search in line:
                    list_of_results.append((line.rstrip()))  

【问题讨论】:

    标签: python parsing pdf


    【解决方案1】:

    尝试这个 :

    使用 open('text.txt','r') 作为 f1,open("keywords.txt") 作为 f2: st = set(map(str.rstrip, f2)) 对于 f1 中的行: 如果有的话(st 中的单词对应 line.split() 中的单词): 打印(行)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      • 1970-01-01
      • 2020-01-19
      相关资源
      最近更新 更多