我正在尝试使用我的 pdfform-scraper-script 删除一些隐藏的输入,然后再将其写入 csv 文件。但我不断收到标题中提到的错误。相关的代码是:
import glob
import os
import sys
import csv
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdftypes import resolve1
path = 'C:\Users\Wonen\Downloads\Test'
for filename in glob.glob(os.path.join(path, '*.pdf')):
fp = open(filename, 'rb')
#read pdf's
parser = PDFParser(fp)
doc = PDFDocument(parser)
#doc.initialize() # <<if password is required
fields = resolve1(doc.catalog['AcroForm'])['Fields']
row = []
for i in fields:
field = resolve1(i)
name, value = field.get('T'), field.get('V')
#removing 'hidden enter'
if value == None:
print 'ok'
elif value == NotImplementedError:
print 'ok'
elif '\n' in value:
value.replace('\n',' ')
elif '\r' in value:
value.replace('\r',' ')
row.append(value)
writer.writerow(list(reversed(row)))
完整的错误(+输出)是:
ok
ok
回溯(最后一次调用):文件“C:\Python27\Scripts\test3.py”,第 37 行,在 elif '\n' 中的值:TypeError:'PSLiteral' 类型的参数不可迭代
有谁知道如何解决这个问题?