我有很多 PDF,其中包含姓名、地址、联系信息、电子邮件 ID 和更多详细信息等数据。我正在尝试编写一个程序来将此数据转换为文本文件并使用不同的方法来提取信息。我使用了 line.startswith 、 Regex 、字符串切片等方法来提取这些信息并将其存储为变量,我将使用这些变量将其上传到数据库。问题 1:是否有更有效的方法来执行此操作,因为我有超过 1000 个 PDF,并且在某些 PDF 中某些值,例如电子邮件 ID 为空。问题 2:每个 PDf 都有很多人的信息,每个人都有多个联系地址,多个其他信息 0 存储此信息的最佳方式是什么,我如何保存多个地址,每个地址都有自己的唯一信息:
handle.seek(0)
NAME = []
MEMBER_ID = []
R_DATE = []
R_TIME = []
MRN = []
DOB = []
GENDER = []
for line in handle:
line =line.strip()
if line.startswith('CONSUMER:'):
NAME.append(line)
elif line.startswith('MEMBER ID:'):
MEMBER_ID.append(line)
elif line.startswith('DATE:'):
R_DATE.append(line)
elif line.startswith('TIME:'):
R_TIME.append(line)
elif line.startswith('MEMBER REFERENCE NUMBER:'):
MRN.append(line)
elif line.startswith('DATE OF BIRTH:'):
DOB.append(line)
elif line.startswith('GENDER:'):
GENDER.append(line)
Name = (NAME[0][10:]).strip()
Member_Id = (MEMBER_ID[0][11:]).strip()
R_date = (R_DATE[0][5:]).strip()
R_time = (R_TIME[0][5:]).strip()
Mrn = (MRN[0][24:]).strip()
Date_Of_Birth = (DOB[0][15:]).strip()
Gender = (GENDER[0][8:]).strip()
handle.seek(0)
basic_table_dict = {
"PAN_NO" : PAN_NO,
"Consumer Name" : Name,
"Member_Id" : Member_Id,
"R_date" : R_date,
"R_time" : R_time,
"Mrn" : Mrn,
"Date_Of_Birth" : Date_Of_Birth,
"Gender" : Gender
}
print(basic_table_dict)
Address = ""
Category = ""
Residence_code = ""
Date_Reported = ""
printing = False
for line in handle4:
line =line.strip()
if line.startswith('ADDRESS(ES):'):
printing = True
# print(line)
continue
elif line.startswith('EMPLOYMENT INFORMATION :'):
printing = False
# print(line)
break
elif printing:
line.lstrip()
if line.startswith("AADDRESS:" ):
Address = line[8:]
Address1 = True
elif line.startswith("CATEGORY:" ):
Category = line[9:]
Address1 = True
elif line.startswith("RESIDENCE CODE:" ):
Residence_code = line[15:]
Address1 = True
if line.startswith("DATE REPORTED:" ):
Date_Reported = line[14:]
Address1 = True
print(line)
地址数据有点像这样 ADDRESS: *****************
类别:办公室
居住代码:拥有
报告日期:21-11-2017
地址: *************************
类别:永久
居住代码:拥有
报告日期:29-04-2017
地址: ****************************
类别:永久
居住代码:
报告日期:2017 年 4 月 18 日