这听起来像是有了文本在页面上的位置将大大帮助你。我建议使用PyMuPDF来提取包含位置数据的文本,这样就可以找到一行。在
下面是一个代码示例,用于获取带有位置的*.csv文本文件。希望这能让您开始使用Python挖掘信息。在#!python3.3
""" Use PyMuPDF to extract text to *.csv file. """
import csv
import json
import os
import sys
import fitz
assert len(sys.argv) == 2, 'Pass file name as parameter'
srcfilename = sys.argv[1]
assert os.path.isfile(srcfilename), 'File {} does not exist'.format(srcfilename)
dstfilename = '{}.csv'.format(srcfilename)
with open(dstfilename, 'w', encoding='utf-8', errors='ignore', newline='') as dstfile:
writer = csv.writer(dstfile)
writer.writerow([
'PAGE',
'X1',
'Y1',
'X2',
'Y2',
'TEXT',
])
document = fitz.open(srcfilename)
for page_number in range(document.pageCount):
text_dict = json.loads(document.getPageText(page_number, output='json'))
for block in text_dict['blocks']:
if block['type'] != 'text':
continue
for line in block['lines']:
for span in line['spans']:
writer.writerow([
page_number,
span['bbox'][0],
span['bbox'][1],
span['bbox'][2],
span['bbox'][3],
span['text'],
])
document.close()
我写了一些代码来挖掘您的PDF文件,并将其放入格式更好的*.csv文件中:
^{pr2}$
你可能要做更多的工作才能得到你想要的东西。在