【发布时间】: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()))
【问题讨论】: