我正在处理代码,并使用warnings库抛出了很多(对我而言)无用的警告.阅读(/扫描)文档我只发现了一种禁用单个函数警告的方法.但我不想改变这么多的代码.
可能有旗帜python -no-warning foo.py吗?
你会推荐什么?
在Python中,我使用pdfminer从pdf中读取文本,并在此消息下面显示代码.我现在收到一条错误消息:
File "/usr/local/lib/python2.7/dist-packages/pdfminer/pdfpage.py", line 124, in get_pages
raise PDFTextExtractionNotAllowed('Text extraction is not allowed: %r' % fp)
PDFTextExtractionNotAllowed: Text extraction is not allowed: <cStringIO.StringO object at 0x7f79137a1
ab0>
Run Code Online (Sandbox Code Playgroud)
当我用Acrobat Pro打开这个pdf时,它证明它是安全的(或"读保护").但是,从这个链接,我读到有很多服务可以轻松禁用这种读保护(例如pdfunlock.com.当潜入pdfminer的源代码时,我看到上面的错误是在这些行上生成的.
if check_extractable and not doc.is_extractable:
raise PDFTextExtractionNotAllowed('Text extraction is not allowed: %r' % fp)
Run Code Online (Sandbox Code Playgroud)
由于有许多服务可以在一秒钟内禁用这种读保护,我认为这很容易做到.它似乎.is_extractable是一个简单的属性doc,但我认为它不像.is_extractable改为True 那么简单.
有谁知道如何使用Python禁用pdf上的读保护?欢迎所有提示!
================================================
您将在下面找到我目前从非读保护中提取文本的代码.
def getTextFromPDF(rawFile):
resourceManager = PDFResourceManager(caching=True)
outfp = StringIO()
device = TextConverter(resourceManager, outfp, codec='utf-8', laparams=LAParams(), imagewriter=None)
interpreter = PDFPageInterpreter(resourceManager, …Run Code Online (Sandbox Code Playgroud)