好友
阅读权限10
听众
最后登录1970-1-1
|
数电发票的正则式很简单,一个就可以了,但是各类税盘开出的电子发票格式多多少少都各有差异,单个的正则式很难解决,有些提取的文字单位前面就不带名称两个字。
如果是正常的电子发票可以用定位提高识别率:
bboxes = [(x1, y1, x2, y1_1), (x1, y3, x2, y3_1), (x1, y2, x3, y2_1), (x1, y4, x4, page_height)
, (x1, y2, x5, y2_1), (x6, y5, x7, y6)]
text1 = "" # 购售方
text2 = "" # 销买方
text3 = "" # 货物名称
text4 = "" # 货物名称'数电'
text5 = "" # 通行费
text6 = "" # 备注
for idx, bbox in enumerate(bboxes):
# 使用矩形区域的坐标裁剪文本
cropped_text = page.within_bbox(bbox).extract_text()
if idx == 0:
text1 += cropped_text
elif idx == 1:
text2 += cropped_text
elif idx == 2:
text3 += cropped_text
elif idx == 3:
text4 += cropped_text
elif idx == 4:
text5 += cropped_text
elif idx == 5:
text6 += cropped_text |
|