python - 在非结构化数据中搜索文本
问题描述
我已经编写了一部分代码来使用 python 从图像中读取文本。图片是发票。
import pytesseract as tess
tess.pytesseract.tesseract_cmd = r'C:\Users\Me\AppData\Local\Tesseract-OCR\tesseract.exe'
from PIL import Image
img = Image.open('C:/Users/Me/Desktop/PM/Invoice Formats/TestInv.png')
text = tess.image_to_string(img)
print(text)
代码的结果是发票文本。我有多张不同格式的发票。谁能帮我从这些非结构化文本中提取发票编号、发票日期和发票金额?
对于少数发票,得到的文本有点像这样。对于其他人来说是不同的
ABC Manufacturing Corporation
Invoice 1111 HHH BBB
‘MyCity, AB'11111-111'
(111)111-1111
My exporter details
\xyz.com
Page: 1 of 2
invoice No, b123456
Date: 01/02/2019,
‘My Oil Products My Bill-To No. 3333
PO Box 1234, Account Number.: 12345
sdlfjsdlf slsdo
Invoice Summary
Delivery Terms:
Payment Terms:
Contact:
DELIVERY POINT
Net 20 days date of invoice
MY NAME
111-111-1111
111-111-1111
abc@xyz.com
Copies of Invoices and Delivery Notes are available on
my url/ check site/ here.
Hf you have any, further questions relating to, your Invoice,
lease contact MY NAME immediately on
111111111
Quantity - Price uni
1000 KG KM = 1000M — KG = Kilogram
Hours Litre M3 = Cubic meter
EA = Each) Normal Cubic Meter
Pounds 7OF, 1atm)
Product Price |
Product Price 1000.28
Net value 1000.28
Total to be paid INR 80000.28
提前谢谢。
解决方案
让我向您展示一个提取日期的示例,然后您可以推断以提取其他日期:
date = text.split('Date: ')[1].split(',')[0]
print(date)
'01/02/2019'
推荐阅读
- scala - 如何在 flink 中统一度量指标
- javascript - 绑定时特殊字符后的AngularJs换行
- android - 如何阻止 Android WebView 更改标头的大小写?
- android - 如何将 Activity 对象传递给 onBindViewHolder 方法以在 getScaledBitmap 方法中使用该对象
- c++ - 使用较新的 boost 库和使用旧版本的预编译二进制文件
- php - 无法从数据库中获取 int 并使用它 PHP
- azure - 如何使用我在 Azure Active Directory 中创建的应用程序注册本地创建的应用程序?
- python - Pygame 蛇吃自己
- r - 打印数据集的 2 个连续数据条目的第一个和最后一个值以绘制差异 - 在 R 中
- javascript - 在 Ajax 上获取 PDF 的输出流并在另一个文档上打开它