小工具知识网

当前位置: 首页 > 行业知识 > camelot pdf提取表格实践(记录)

行业知识

camelot pdf提取表格实践(记录)

2026-12-02 23:00:34 来源:互联网转载

参考:

巧���Python的camelot库批量提取PDF发票信息

关于文本pdf的表格抽取

AttributeError: module ‘camelot‘ has no attribute ‘read_pdf‘及类似问题解决办法

camelot 参数

https://blog.csdn.net/INTSIG/article/details/123000010

报错解决:

ModuleNotFoundError: No module named ‘Workbook’ xlwt,是版本太低,升级版本即可。 pip install --upgrade xlwt

介绍:

camelot方法有两种解析模式:流解析(stream)、格子解析(lattice),其中格子解析能够保留表格完整的样式,对于复杂表格来说要优于流解析模式。同时,camelot方法默认格子解析(lattice),而采用这种解析方式,需要安装ghostscript。

camelot是一个可以从可编辑的pdf文档中抽取表格的开源框架,与pdfplumber相比,其功能完备性差了点,除了表格抽取之外,并不能用它从pdf文档中解析出字符、单词、文本、线等较为低层次的对象。

下载ghostscript https://www.ghostscript.com/releases/gsdnld.html

参数

代码

import camelotimport pandas as pd# 使用Camelot读取PDF文件中的表格tables = camelot.read_pdf('pdf.pdf', pages='all', flavor='lattice')# 将所有表格转换为 DataFrame 并合并all_data = pd.concat([table.df for table in tables], ignore_index=True)all_data.to_excel('all_data.xlsx',index=False)

识别效果:不太理想,文本排序有问题。pdfplumber提取表格效果会更好,但是也有少部分数据可能错行

上一篇:淘金果园偷菜秘籍大揭秘!独家攻略分享!

下一篇:穿越火线服务器怎么进不去?