【问题标题】:Python Tika cannot parse pdf from urlPython Tika 无法从 url 解析 pdf
【发布时间】:2023-03-12 19:10:01
【问题描述】:

python 用于解析在线 pdf 以备将来使用。我的代码如下。

from tika import parser
import requests
import io
url = 'https://www.whitehouse.gov/wp-content/uploads/2017/12/NSS-Final-12-18-2017-0905.pdf'
response = requests.get(url)
with io.BytesIO(response.content) as open_pdf_file:
    pdfFile = parser.from_file(open_pdf_file)
print(pdfFile)

但是,它显示

AttributeError: '_io.BytesIO' 对象没有属性 'decode'

我以How can i read a PDF file from inline raw_bytes (not from file)?为例

在示例中,它使用的是 PyPDF2。但我需要使用 Tika,因为 Tika 的结果比 PyPDF2 更好。

感谢您的帮助

【问题讨论】:

    标签: python apache-tika tika-server


    【解决方案1】:

    为了使用 tika,您将 need to have JAVA 8 installed。您需要检索和打印 pdf 内容的代码如下:

    from tika import parser
    
    url = 'https://www.whitehouse.gov/wp-content/uploads/2017/12/NSS-Final-12-18-2017-0905.pdf'
    
    pdfFile = parser.from_file(url)
    
    print(pdfFile["content"])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 2019-04-05
      相关资源
      最近更新 更多