[英]Error writing 3000+ pdf files in one txt file with python 3
我正在尝试从一个 txt 文件中的 3000 多个 PDF 中提取文本(而我必须从每一页中删除标题):
for x in range(len(files)-len(files)+15):
pdfFileObj=open(files[x],'rb')
pdfReader=PyPDF2.PdfFileReader(pdfFileObj)
for pageNum in range(1,pdfReader.numPages):
pageObj=pdfReader.getPage(pageNum)
content=pageObj.extractText()
removeIndex = content.find('information.') + len('information.')
newContent=content[removeIndex:]
file.write(newContent)
file.close()
但是,我收到以下错误:
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufb02' in position 5217: character maps to <undefined>
我无法检查每个 PDF 的编码,所以我只使用了 replace()。 下面是工作代码:
for x in range(len(files)):
pdfFileObj=open(os.path.join(filepath,files[x]),'rb')
for pageNum in range(1,pdfReader.numPages):
pageObj=pdfReader.getPage(pageNum)
content=pageObj.extractText()
removeIndex = content.find('information.') + len('information.')
newContent=content[removeIndex:]
newContent=newContent.replace('\n',' ')
newContent=newContent.replace('\ufb02','FL')
file.write(str(newContent.encode('utf-8')))
file.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.