我使用PyPDF2和tika从.pdf和.htm文件中提取文本。 我遇到了以下错误: “PyPDF2。utils.PdfReadError:未找到EOF标记“
我看过很多关于这个问题的帖子,但是没有一篇包含解决方案。在
下面是我使用的代码:
from xlwt import Workbook
import PyPDF2, os
from tika import parser
wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
sheet1.write(0, 0, 'file name')
sheet1.write(0, 1, 'file content')
pdfFiles = []
folderPath = 'C:/Users/Turing/Desktop/workingFiles' #! define the path for the folder including input files
for filename in os.listdir(folderPath):
if filename.endswith('.htm') or filename.endswith('.pdf'):
pdfFiles.append(filename)
pdfFiles.sort(key=str.lower)
row = 0
for filename in pdfFiles:
row = row + 1
#print(filename)
sheet1.write(row, 0, filename) # write the name of the file to column number 0 of output
filename = folderPath+'\\'+filename
pdfFileObj = open(filename, 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
raw = parser.from_file(filename)
#print(raw['content'])
sheet1.write(row, 1, raw['content']) # write the content of the input doc to column number 1 of the output
wb.save('MRS.xls')
我上传了one of the problematic files供你参考。在
您正在使用PyPDF2.PdfFileReader读取一个HTML文件,该文件需要一个PDF文件。 可能最容易分成
然后分别解析它们。在
相关问题 更多 >
编程相关推荐