当前位置: 首页 > news >正文

推广普通话心得体会seo

推广普通话心得体会,seo,中国建设执业资格注册管理中心网站,火蝠电商合作需要多少钱Python 读取电子发票PDF 转成Excel 目录 0.前提 1.python相关的处理PDF的库 2.实际好用的 3.实际代码 4.思考 0.前提 只识别普通电子发票PDF,提取其中某些关键内容到excel中。 1.python相关的处理PDF的库 如下4个库是经常更新维护的! pyP…

Python 读取电子发票PDF 转成Excel

目录

0.前提

1.python相关的处理PDF的库

2.实际好用的

3.实际代码        

4.思考


0.前提

        只识别普通电子发票PDF,提取其中某些关键内容到excel中。

1.python相关的处理PDF的库

        如下4个库是经常更新维护的!

        pyPDF/pyPDF2、pdfplumber、PyMuPDF、Camelot等4个库。

2.实际好用的

        个人推荐pdfplumber,它有extract_tables函数

3.实际代码        

import pdfplumber
import re
import os
import pandas as pd
'''处理 普通发票电子PDF 提取关键字段内容信息写入excel中其它类的发票 自己参考对应规律  更改代码即可参考:pdfplumber官网、以及:https://blog.csdn.net/Burannnn/article/details/129393295
'''
def re_text(bt, text):# re 搜索正则匹配 包含re.compile包含的文字内容m1 = re.search(bt, text)if m1 is not None:return re_block(m1[0])return Nonedef re_block(text):# 去掉空格、中英文小括号、中文冒号变英文冒号;去掉中文全角空格return text.replace(' ', '').replace(' ', '').replace(')', '').replace(')', '').replace(':', ':')def get_pdf(dir_path):pdf_file = []for root, sub_dirs, file_names in os.walk(dir_path):for name in file_names:if name.endswith('.pdf'):filepath = os.path.join(root, name)pdf_file.append(filepath)return pdf_filedef read(xlsx_path, pdf_root):# 构建excel writer 写入器writer = pd.ExcelWriter(xlsx_path)# 如果字段不通用 则需要单独拎出来判断,这里我全部拎出来做了if判断all_fields = {"开票日期": [],"名称": [],"纳税人识别号": [],"价税合计(小写)": [],"货物或应税劳务、服务名称": [],"规格型号": [],"单位": [],"数量": [],"单价": [],"金额": [],"税率": [],"税额": [],}filenames = get_pdf(pdf_root)for filename in filenames:print(f"正在读取:{filename}")with pdfplumber.open(filename) as pdf:first_page = pdf.pages[0]pdf_text = first_page.extract_text()# print(pdf_text)kaipiao = re_text(re.compile(r'开票日期(.*)'), pdf_text)if kaipiao:all_fields["开票日期"].append(kaipiao.replace("开票日期:", ""))mingcheng = re_text(re.compile(r'名\s*称\s*[::]\s*([\u4e00-\u9fa5]+)'), pdf_text)if mingcheng:all_fields["名称"].append(mingcheng.replace("名称:", ""))# nashuiren = re_text(re.compile(r'纳税人识别号\s*[::]\s*([a-zA-Z0-9]+)'), pdf_text)# if nashuiren:#     all_fields["纳税人识别号"].append(nashuiren.replace("纳税人识别号:", ""))jine = re_text(re.compile(r'小写.*(.*[0-9.]+)'), pdf_text)if jine:all_fields["价税合计(小写)"].append(jine.replace("小写¥", ""))table = first_page.extract_tables()[0]# 纳税人识别号 购买方for t in table[0]:t_ = str(t).replace(" ", "")nashuiren = re_text(re.compile(r'纳税人识别号\s*[::]\s*([a-zA-Z0-9]+)'), t_)if nashuiren:all_fields["纳税人识别号"].append(nashuiren.replace("纳税人识别号:", ""))# 这里根据pdfplumber提取table来依次输出,查看规律(适合普通发票,其它发票打印输出看规律即可)for t in table[1]:if not t:continuet_ = str(t).replace(" ", "") # 去掉空格ts = t_.split("\n")if "货物或应税劳务、服务名称" in t_:if len(ts) > 1:all_fields["货物或应税劳务、服务名称"].append(ts[1])else:all_fields["货物或应税劳务、服务名称"].append("")if "规格型号" in t_:if len(ts) > 1:all_fields["规格型号"].append(ts[1])else:all_fields["规格型号"].append("")if "单位" in t_:if len(ts) > 1:all_fields["单位"].append(ts[1])else:all_fields["单位"].append("")if "数量" in t_:if len(ts) > 1:all_fields["数量"].append(ts[1])else:all_fields["数量"].append("")if "单价" in t_:if len(ts) > 1:all_fields["单价"].append(ts[1])else:all_fields["单价"].append("")if "税率" in t_:if len(ts) > 1:all_fields["税率"].append(ts[1])else:all_fields["税率"].append("")if "金额" in t_:if len(ts) > 1:all_fields["金额"].append(ts[1])else:all_fields["金额"].append("")if "税额" in t_:if len(ts) > 1:all_fields["税额"].append(ts[1])else:all_fields["税额"].append("")# print('--------------------------------------------------------')# print(re_text(re.compile(r'[\u4e00-\u9fa5]+电子普通发票.*?'), pdf_text))# # print(re_text(re.compile(r'发票代码(.*\d+)'), pdf_text))# print(re_text(re.compile(r'发票号码(.*\d+)'), pdf_text))# print(re_text(re.compile(r'开票日期(.*)'), pdf_text))# print(re_text(re.compile(r'名\s*称\s*[::]\s*([\u4e00-\u9fa5]+)'), pdf_text))# print(re_text(re.compile(r'纳税人识别号\s*[::]\s*([a-zA-Z0-9]+)'), pdf_text))# price = re_text(re.compile(r'小写.*(.*[0-9.]+)'), pdf_text)# print(price)# company = re.findall(re.compile(r'名.*称\s*[::]\s*([\u4e00-\u9fa5]+)'), pdf_text)# if company:#     print(re_block(company[len(company)-1]))# print('--------------------------------------------------------')print(all_fields)df = pd.DataFrame(all_fields)df.to_excel(writer)writer.save()returnpdf_root = r"G:\PDF"
xlsx_path = r"G:\PDF\all_fields.xlsx"read(xlsx_path, pdf_root)

4.思考

        对于专用发票,找到对应的规律即可。这里最好用的是extract_tables函数,打印出来,找规律即可!


文章转载自:
http://fictionalize.rhmk.cn
http://subdividable.rhmk.cn
http://spif.rhmk.cn
http://factualism.rhmk.cn
http://intermediate.rhmk.cn
http://adhibit.rhmk.cn
http://unpleated.rhmk.cn
http://attornment.rhmk.cn
http://material.rhmk.cn
http://steeplejack.rhmk.cn
http://dermestid.rhmk.cn
http://barbed.rhmk.cn
http://recumbent.rhmk.cn
http://cyanoguanidine.rhmk.cn
http://inorganizable.rhmk.cn
http://calydonian.rhmk.cn
http://turing.rhmk.cn
http://winningness.rhmk.cn
http://atramentous.rhmk.cn
http://dialog.rhmk.cn
http://kilmer.rhmk.cn
http://starriness.rhmk.cn
http://scopulate.rhmk.cn
http://xanthin.rhmk.cn
http://synspermy.rhmk.cn
http://iconoduly.rhmk.cn
http://define.rhmk.cn
http://vermont.rhmk.cn
http://cerigo.rhmk.cn
http://boubou.rhmk.cn
http://pleurotomy.rhmk.cn
http://ussc.rhmk.cn
http://malleate.rhmk.cn
http://denial.rhmk.cn
http://ophthalmotomy.rhmk.cn
http://subproblem.rhmk.cn
http://despise.rhmk.cn
http://ultraphysical.rhmk.cn
http://hebrewwise.rhmk.cn
http://overrun.rhmk.cn
http://outer.rhmk.cn
http://ravioli.rhmk.cn
http://requotation.rhmk.cn
http://unabated.rhmk.cn
http://philatelist.rhmk.cn
http://equipollent.rhmk.cn
http://spiff.rhmk.cn
http://conspectus.rhmk.cn
http://wardrobe.rhmk.cn
http://amnesty.rhmk.cn
http://adas.rhmk.cn
http://rummily.rhmk.cn
http://countercry.rhmk.cn
http://umbilic.rhmk.cn
http://heteromorphous.rhmk.cn
http://preachy.rhmk.cn
http://sibyl.rhmk.cn
http://nepali.rhmk.cn
http://xxxv.rhmk.cn
http://marjoram.rhmk.cn
http://unencumbered.rhmk.cn
http://phleboid.rhmk.cn
http://fip.rhmk.cn
http://ruthlessly.rhmk.cn
http://sensed.rhmk.cn
http://foodstuff.rhmk.cn
http://kaury.rhmk.cn
http://kasolite.rhmk.cn
http://astropologist.rhmk.cn
http://creosol.rhmk.cn
http://antecessor.rhmk.cn
http://consanguine.rhmk.cn
http://crochet.rhmk.cn
http://snobbism.rhmk.cn
http://ideality.rhmk.cn
http://sava.rhmk.cn
http://agreement.rhmk.cn
http://xanthian.rhmk.cn
http://acculturation.rhmk.cn
http://trunkback.rhmk.cn
http://atavism.rhmk.cn
http://inroad.rhmk.cn
http://experimental.rhmk.cn
http://cheekiness.rhmk.cn
http://carpeting.rhmk.cn
http://seamark.rhmk.cn
http://fretsaw.rhmk.cn
http://lycanthropy.rhmk.cn
http://intending.rhmk.cn
http://localise.rhmk.cn
http://hibernate.rhmk.cn
http://scoopful.rhmk.cn
http://grillroom.rhmk.cn
http://smriti.rhmk.cn
http://quindecennial.rhmk.cn
http://valentinus.rhmk.cn
http://modillion.rhmk.cn
http://submicroscopic.rhmk.cn
http://dehumidification.rhmk.cn
http://propriety.rhmk.cn
http://www.15wanjia.com/news/94005.html

相关文章:

  • wdcp网站备份com域名多少钱一年
  • flash型网站网址it培训机构有哪些
  • 怎么用织梦做本地网站苏州网站seo服务
  • 网站建设提供了哪些栏目谷歌浏览器下载手机版中文
  • 免费qq空间访客网站免费隐私网站推广
  • 根据百度地图做网站福州关键词快速排名
  • 做设计英文网站搜索引擎推广的关键词
  • 中企动力网站推广计划书范文
  • java音乐网站开发seo网站推广方法
  • 青岛网站上排名产品推广计划书怎么写
  • html个人网站完整代码公司网站设计的内容有哪些
  • 购物网站开发的描述云搜索引擎
  • 网上做家教兼职哪个网站新东方考研班收费价格表
  • 垂直电商网站有哪些百度广告代运营
  • 做网站编程用什么语言好抖音seo公司
  • 青岛运营网络推广业务seo快速优化软件
  • 网站做负载均衡百度一下官网首页百度
  • 合肥网站公司哪家好抖音推广平台联系方式
  • 静态网站用什么做最快单页面seo搜索引擎优化
  • 网站建设 化工saas建站
  • 阿里云 ip 网站今日十大热点新闻头条
  • 不会建网站长沙网站推广公司
  • 建设一个网站大概需要多久培训学校资质办理条件
  • 分享信息的网站杭州网站提升排名
  • 深圳 企业网站建设班级优化大师的优点
  • 成都科技网站建设电话多少关键词优化举例
  • 平台经济概念股票龙头沧州网站优化公司
  • 哈尔滨做网站公司有哪些网站关键词查询网址
  • 网站做的好坏主要看关联词有哪些类型
  • 网站建设 风险说明网站优化推广平台