【问题标题】:I passed the file object but still getting parse error with slate3k我通过了文件对象,但仍然遇到 slate3k 的解析错误
【发布时间】:2019-08-27 07:54:34
【问题描述】:

我正在尝试使用 "slate3k" 读取 pdf 文件的文本数据。对我来说似乎很好。但是我遇到了解析错误

我一直在使用 "python3.7" 。

import slate3k

with open("/home/am-it/Desktop/PythonLearning/pdf_practice/invoice-1.pdf","rb")as file:
    doc = slate3k.PDF(file)
    print(doc)

以上代码的输出应该是pdf中的文本。但实际输出是

 "Traceback (most recent call last):
  File "/home/am-it/Desktop/PythonLearning/pdf_practice/invoslate.py", line 4, in <module>
    doc = slate3k.PDF(file)
  File "/home/administrator/.local/lib/python3.7/site-packages/slate3k/classes.py", line 59, in __init__
    self.doc = PDFDocument()
TypeError: __init__() missing 1 required positional argument: 'parser'" 

我已经传递了正确的文件对象,但仍然出现错误。所以请赐教

【问题讨论】:

  • 看起来 slate3k 中可能存在错误和/或您使用的 pdfminer 版本不兼容。
  • 谢谢@Iguananaut ....我卸载了pdfminer.six ...它开始工作

标签: python python-3.x slate


【解决方案1】:

老兄, 在这部分代码中: 以 open("/home/am-it/Desktop/PythonLearning/pdf_practice/invoice-1.pdf","rb") 为文件:

你必须写文件名加上扩展名而不是路径。 所以,试试这个: 以 open("invoice-1.pdf","rb") 作为文件:

【讨论】:

【解决方案2】:

我的用单引号和不缩进打印效果很好

import slate3k as slt
with open('pdfPythonTest.pdf','rb') as f:
    extracted_text=slt.PDF(f)
print(extracted_text)

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    • 1970-01-01
    • 2022-12-02
    • 2012-12-27
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多