python - 从pdf中提取数据的最佳方法是什么
问题描述
我有数千个 pdf 文件需要从中提取数据。这是一个示例pdf。我想从示例 pdf 中提取此信息。
我对 nodejs、python 或任何其他有效方法持开放态度。我对python和nodejs知之甚少。我尝试在这段代码中使用 python
import PyPDF2
try:
pdfFileObj = open('test.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pageNumber = pdfReader.numPages
page = pdfReader.getPage(0)
print(pageNumber)
pagecontent = page.extractText()
print(pagecontent)
except Exception as e:
print(e)
但我被困在如何查找采购历史记录上。从 pdf 中提取采购历史的最佳方法是什么?
解决方案
pdfplumber is the best option. [Reference]
Installation
pip install pdfplumber
Extract all the text
import pdfplumber
path = 'path_to_pdf.pdf'
with pdfplumber.open(path) as pdf:
for page in pdf.pages:
print(page.extract_text())
推荐阅读
- python - KeyError:密钥长度超过索引深度 - 熊猫 MultiIndex
- unicode - print() unicode 字符时 python 3.5 与 3.6 的区别?
- c# - 使用 c# 生成 html 电子邮件内容
- swift - 缓存实现方法
- android - gradle 更新到 3.3.0 alpha13 后,Android 资源编译失败
- vectorization - How are the matrix values calculated in Octave when we divide a scalar with a vector?
- python - 为什么在使用这些“while 循环”时我的窗口没有出现在 python 中?
- animation - Why is it difficult to use Quaternions for the LBS(Linear Blend Skinning) formula?
- django - 如何在 Django 管理界面更改表单中更改用户名验证方式?
- javascript - 如何使用 sinon 覆盖函数作为参数的函数的单元测试