我必须从pdf文件中提取文本。为此,我正在使用python 2.7.7 PyPDF2是我用来提取文本的库。但是有些单词是串联在一起的,因此“ list_of_words”列表中的单词数量较少。 另外,我认为由于此r2列表为空。我应该怎么做才能使此列表r2列表不为空?以下是处理它的代码部分:
filename ='FICC_Rpt_Click_Arrow_Save_as_PDF_thru_Browser.pdf'
pdfFileObj = open(filename,'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
num_pages = pdfReader.numPages
count = 0
text = ""
while count < num_pages:
pageObj = pdfReader.getPage(count)
count +=1
if(count>=1):
text += pageObj.extractText()
if text != "":
text = text
print("s")
text = text.encode('ascii','ignore').lower()
r2=[]
r3=[]
r4=[]
r5=[]
sett_price=[]
nr_long=[]
nr_short=[]
nr_debit=[]
nr_credit=[]
cusip=[]
list_of_words = text.split()
indices = [i for i, x in enumerate(list_of_words) if(x == "net")]
print(indices)
for i in indices:
if (list_of_words[i+5]=="net"):
r2.append(list_of_words[i+1])
r3.append(list_of_words[i+2])
我希望列表r2充满数据,但实际上列表r2为空