[英]Solving “EOF market not found error” PyPDF2
我正在使用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')
我已經上傳了有問題的文件之一供您參考。
您正在使用PyPDF2.PdfFileReader讀取HTML文件,該文件需要PDF文件。 可能最容易分解為
pdfFiles = []
htmFiles = []
for filename in os.listdir(folderPath):
if filename.endswith('.pdf'):
pdfFiles.append(filename)
if filename.endswith('.htm'):
htmFiles.append(filename)
並分別解析它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.