python - 从S3存储桶python的pdf文件中提取文本
问题描述
我的 AWS s3 存储桶中有多个格式文件,例如 pdf、doc、rtf、odt、png,我需要从中提取文本。我已经设法通过它们的路径获取内容列表。现在根据文件类型,我将使用不同的库从文件中提取文本。由于文件可能有数千个,我需要直接从 s3 中提取文本,而不是下载。
filespath=['https://abc.s3.ap-south-1.amazonaws.com/DocumentOnPATest', 'https://abc.s3.ap-south-1.amazonaws.com/IndustryReport2019.pdf', 'https://abc.s3.ap-south-1.amazonaws.com/receipt.png', 'https://abc.s3.ap-south-1.amazonaws.com/sample.rtf', 'https://abc.s3.ap-south-1.amazonaws.com/sample1.odt']
bucketname =abc
我尝试了一些东西,但它给了我错误
for path in filespath:
ext=pathlib.Path(path).suffix
if ext=='.pdf':
pdf_file=PyPDF2.PdfFileReader(path)
print(pdf_file.extractText())
但我收到一个错误
File "F:\Projects\FileExtractor\fileextracts3.py", line 28, in <module>
pdf_file=PyPDF2.PdfFileReader(path)
File "C:\ProgramData\Anaconda3\lib\site-packages\PyPDF2\pdf.py", line 1081, in __init__
fileobj = open(stream, 'rb')
OSError: [Errno 22] Invalid argument: 'https://abc.s3.ap-south-1.amazonaws.com/IndustryReport2019.pdf
请帮我领导。谢谢
解决方案
PyPDF2
不支持直接从 s3 读取。您需要先在本地下载它们。
推荐阅读
- microsoft-graph-api - Loopback 4 实现 Microsoft Graph API
- python - 删除文档会引发 PermissionError:[WinError 32]
- jquery - 仅在使用 ajax 重新加载页面内容后,如何运行 js/jquery 函数?
- flutter - SingleChildScrollView 不起作用,出现底部溢出错误
- windows - Azure IoT Edge EFLOW 安装中断,现在验证失败
- mysql - Laravel查询如何使数据库中的3个数据在视图表中变为1
- flutter - 在 ThemeData 中的 AppBarTheme 中定义 AppBar 的渐变
- python-3.x - 在窗口 tkinter 中显示消息
- regex - 如何从bash中的变量中删除匹配的动态字符串部分
- bash - 将子字符串移动到另一行