Python Tika 无法解析来自 url 的 pdf

Python Tika cannot parse pdf from url

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' object has no attribute 'decode'

我从

中举了个例子

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

感谢您的帮助

为了使用 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"])