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

做水果网站行seo最强

做水果网站行,seo最强,上海建筑设计公司排名前10,网站的开发文章目录 前言一、pdfplumber模块1.1 pdfplumber的特点1.2 pdfplumber.PDF类1.3pdfplumber.Page类 二 pdfplumber的使用2.1 加载PDF2.2 pdfplumber.PDF 类2.3 pdfplumber.Page 类2.4 读取PDF2.5 读取PDF文档信息2.6 查看总页数2.7 查看总页数读取第一页的宽度,页高等…

文章目录

  • 前言
  • 一、pdfplumber模块
    • 1.1 pdfplumber的特点
    • 1.2 pdfplumber.PDF类
    • 1.3pdfplumber.Page类
  • 二 pdfplumber的使用
    • 2.1 加载PDF
    • 2.2 pdfplumber.PDF 类
    • 2.3 pdfplumber.Page 类
    • 2.4 读取PDF
    • 2.5 读取PDF文档信息
    • 2.6 查看总页数
    • 2.7 查看总页数读取第一页的宽度,页高等信息
    • 2.8 读取文本
    • 2.9 读取表格
    • 3.1 pdfplumber提取表格数据
    • 示例
      • 读取文字
      • 读取表格

前言

PDF是一种编写文档格式,便于跨操作系统传播文档。Python的开源库 pdfplumber,可以较为方便地获取pdf的各种信息,包含pdf的基本信息(作者、创建时间、修改时间…)及表格、文本、图片等信息,基本可以满足较为简单的格式转换功能。

一、pdfplumber模块

1.1 pdfplumber的特点

  • 1、可以轻松访问有关每个PDF对象的详细信息。
  • 2、可以提取文本和表格的更高级别,可以自定义的方法。
  • 3、支持紧密集成的可视化调试。
  • 4、有通过裁剪框过滤对象等实用功能。

pdfplumber中有两个基础类,PDF和Page。PDF用来处理整个文档,Page用来处理整个页面。

1.2 pdfplumber.PDF类

  • .metadata: 获取pdf基础信息,返回字典
  • pages 一个包含pdfplumber.Page实例的列表,每一个实例代表pdf每一页的信息。

1.3pdfplumber.Page类

pdfplumber核心功能,对PDF的大部分操作都是基于这个类,包括提取文本、表格、尺寸等。

二 pdfplumber的使用

2.1 加载PDF

调用pdfplumber.open(x)加载PDF, 其中x可以有以下几种格式:a、PDF文件路径。b、文件对象, 以字节流形式加载。c、类文件对象, 以字节流形式加载。

读取 PDF代码:pdfplumber.open("路径/文件名.pdf",password="test",laparams={"line_overlap":0.7})
解读:
passworf:加载受密码保护的PDF要传递password关键字参数。
laparams:将布局分析参数设置为pdfminer.six的布局引擎,传递laparams关键字参数。

2.2 pdfplumber.PDF 类

pdfplumber.PDF 类代表一个PDF文件,主要有两个属性。

属性说明
.metadata元数据键值对字典,摘自PDF的“信息”。通常包括“CreationDate"(创建日期)、“ModDate"(修改日期)、Producer"(创建者)等。
.pages包含pdfplumber . Page(页实例)的列表。

2.3 pdfplumber.Page 类

pdfplumber.Page是pdfplumber核心,大部分的操作都是围绕此类进行。

属性
.page_number页码
.width页面宽
.height页面长
.objects/ .chars /.lines /. rects /. curves / . images属性中的每一个都是一个列表,每个列表都是嵌入在页面上的每个此类对象包含一个字典。

2.4 读取PDF

import pdfplumber
import pandas as pdwith pdfplumber.open("ag-energy-round-up-2017-02-24.pdf") as pdf:

2.5 读取PDF文档信息

with pdfplumber.open("ag-energy-round-up-2017-02-24.pdf") as pdf:print(pdf.metadata)

结果

{‘Title’: ‘National Ag Energy’, ‘Author’: ‘LGMN, Des Moines, IA’, ‘Keywords’: ‘National Ag Energy ethanol biodiesel bioenergy’, ‘CreationDate’: “D:20170224133144-06’00’”, ‘ModDate’: “D:20170224133144-06’00’”, ‘Producer’: ‘Microsoft® Excel® 2013’, ‘Creator’: ‘Microsoft® Excel® 2013’}

2.6 查看总页数

len(pdf.pages)

2.7 查看总页数读取第一页的宽度,页高等信息

first_page = pdf.pages[0]
# 查看页码
print('页码:', first_page.page_number)# 查看页宽print('页宽:', first_page.width)
# 查看页高
print('页高:', first_page.height)

2.8 读取文本

with pdfplumber.open("继(吊岩坪)110-2018-05(都吊东线2区).pdf") as pdf:# 第一页pdfplumber.Page实例first_page = pdf.pages[0]text = first_page.extract_text()print(text)

2.9 读取表格

import pdfplumber
import pandas as pdwith pdfplumber.open("继(吊岩坪)110-2018-05(都吊东线2区).pdf") as pdf:page_third = pdf.pages[0]table_1 = page_third.extract_table()#table_df = pd.DataFrame(table_1[1:], columns=table_1[0])print(table_1)

##三 、示例

3.1 pdfplumber提取表格数据

提取表格数据主要用到extract_tables()和extract_table()两种方法,这两种提取方式各有不同。
extract_tables()方法——输出文档所有表格,返回一个嵌套列表。

with pdfplumber.open(r'继(吊岩坪)110-2018-05(都吊东线2区).pdf') as pdf_info:  # 打开pdfpage_one = pdf_info.pages[0]page_one_table = page_one.extract_tables()  # 获取pdf第一页的所有表格数据for row in page_one_table:print('第一页的表格数据:', row)

extact_table()方法——不会返回文档的所有表格,仅返回行数最多的表格数据。如存在多个行数相等的表格,则默认输出顶部表格数据。表格的每一行都为一个单独的列表,列表中的元素即为原表格的各个单元格的数据。

示例

# 提取pdf表格数据并保存到excel中
import pdfplumber
from openpyxl import Workbookclass PDF(object):def __init__(self, file_path):self.pdf_path = file_path# 读取pdftry:self.pdf_info = pdfplumber.open(self.pdf_path)print('读取文件完成!')except Exception as e:print('读取文件失败:', e)# 打印pdf的基本信息、返回字典,作者、创建时间、修改时间/总页数def get_pdf(self):pdf_info = self.pdf_info.metadatapdf_page = len(self.pdf_info.pages)print('pdf共%s页' % pdf_page)print("pdf文件基本信息:\n", pdf_info)self.close_pdf()# 提取表格数据,并保存到excel中def get_table(self):wb = Workbook()  # 实例化一个工作簿对象ws = wb.active  # 获取第一个sheetcon = 0try:# 获取每一页的表格中的文字,返回table、row、cell格式:[[[row1],[row2]]]for page in self.pdf_info.pages:for table in page.extract_tables():for row in table:# 对每个单元格的字符进行简单清洗处理row_list = [cell.replace('\n', ' ') if cell else '' for cell in row]ws.append(row_list)  # 写入数据con += 1print('---------------分割线,第%s页---------------' % con)except Exception as e:print('报错:', e)finally:wb.save('\\'.join(self.pdf_path.split('\\')[:-1]) + '\pdf_excel.xlsx')print('写入完成!')self.close_pdf()# 关闭文件def close_pdf(self):self.pdf_info.close()if __name__ == "__main__":file_path = input('请输入pdf文件路径:')pdf_info = PDF(file_path)pdf_info.get_pdf() # 打印pdf基础信息# 提取pdf表格数据并保存到excel中,文件保存到跟pdf同一文件路径下pdf_info.get_table()
import pdfplumber
text_path = r"D:\Project\MyData\Study\GUI\6_GUI编程(第三部分)\第十一章GUI图形用户界面编程.pdf"with pdfplumber.open(text_path) as pdf:print(pdf.pages)#获取pdf文档所有的页,类型是dicttotal_pages = len(pdf.pages)print("total_pages: ",total_pages)page = pdf.pages[0]  #获取第一页print(type(page))  #<class 'pdfplumber.page.Page'># print(page.extract_text())  #获取第一页的内容#fitz读取pdf全文content=""for i in range(0,len(pdf.pages)):# page=content += pdf.pages[i].extract_text()# print(page.extract_text())# print(page.extract_tables())# print(content)

读取文字

import pdfplumber
import pandas as pdwith pdfplumber.open("E:\\600aaa_2.pdf") as pdf:page_count = len(pdf.pages)print(page_count)  # 得到页数for page in pdf.pages:print('---------- 第[%d]页 ----------' % page.page_number)# 获取当前页面的全部文本信息,包括表格中的文字print(page.extract_text())

读取表格

import pdfplumber
import pandas as pd
import rewith pdfplumber.open("E:\\600aaa_1.pdf") as pdf:page_count = len(pdf.pages)print(page_count)  # 得到页数for page in pdf.pages:print('---------- 第[%d]页 ----------' % page.page_number)for pdf_table in page.extract_tables(table_settings={"vertical_strategy": "text","horizontal_strategy": "lines","intersection_tolerance":20}): # 边缘相交合并单元格大小# print(pdf_table)for row in pdf_table:# 去掉回车换行print([re.sub('\s+', '', cell) if cell is not None else None for cell in row])

文章转载自:
http://cynocephalus.qpnb.cn
http://uptodate.qpnb.cn
http://bimolecular.qpnb.cn
http://artmobile.qpnb.cn
http://lobsterback.qpnb.cn
http://plebeian.qpnb.cn
http://overculture.qpnb.cn
http://radiogoniometry.qpnb.cn
http://waterpower.qpnb.cn
http://transplant.qpnb.cn
http://polygynous.qpnb.cn
http://candy.qpnb.cn
http://cheribon.qpnb.cn
http://the.qpnb.cn
http://ceuca.qpnb.cn
http://christie.qpnb.cn
http://suckle.qpnb.cn
http://parvulus.qpnb.cn
http://ismaelian.qpnb.cn
http://beau.qpnb.cn
http://pole.qpnb.cn
http://hera.qpnb.cn
http://seiko.qpnb.cn
http://subsequently.qpnb.cn
http://bicorporeal.qpnb.cn
http://enantiotropic.qpnb.cn
http://ast.qpnb.cn
http://encirclement.qpnb.cn
http://polycotyl.qpnb.cn
http://labor.qpnb.cn
http://lipotropy.qpnb.cn
http://tricotine.qpnb.cn
http://nome.qpnb.cn
http://tortillon.qpnb.cn
http://benumb.qpnb.cn
http://ladleful.qpnb.cn
http://buxom.qpnb.cn
http://scutari.qpnb.cn
http://ineloquent.qpnb.cn
http://deionize.qpnb.cn
http://dilator.qpnb.cn
http://sakellaridis.qpnb.cn
http://battlefield.qpnb.cn
http://caryopsis.qpnb.cn
http://reliquidate.qpnb.cn
http://revetment.qpnb.cn
http://tumefy.qpnb.cn
http://kist.qpnb.cn
http://thwartships.qpnb.cn
http://salutatory.qpnb.cn
http://empiriocriticism.qpnb.cn
http://cutlery.qpnb.cn
http://indebted.qpnb.cn
http://claustrophobe.qpnb.cn
http://plumassier.qpnb.cn
http://turbidly.qpnb.cn
http://pruritic.qpnb.cn
http://rhodesian.qpnb.cn
http://hydroxybenzene.qpnb.cn
http://aviation.qpnb.cn
http://forjudge.qpnb.cn
http://survive.qpnb.cn
http://maronite.qpnb.cn
http://participialize.qpnb.cn
http://horrible.qpnb.cn
http://wipo.qpnb.cn
http://won.qpnb.cn
http://polymorphous.qpnb.cn
http://gonimoblast.qpnb.cn
http://rowena.qpnb.cn
http://psychogenic.qpnb.cn
http://quadrilingual.qpnb.cn
http://gazania.qpnb.cn
http://southampton.qpnb.cn
http://fletschhorn.qpnb.cn
http://atherosclerotic.qpnb.cn
http://concerted.qpnb.cn
http://vorticist.qpnb.cn
http://habitus.qpnb.cn
http://driller.qpnb.cn
http://barbarize.qpnb.cn
http://remnant.qpnb.cn
http://hyperbatically.qpnb.cn
http://unlax.qpnb.cn
http://stoic.qpnb.cn
http://microskirt.qpnb.cn
http://unmoor.qpnb.cn
http://aicpa.qpnb.cn
http://sensorium.qpnb.cn
http://inimitable.qpnb.cn
http://careen.qpnb.cn
http://prolong.qpnb.cn
http://deterge.qpnb.cn
http://aerodonetics.qpnb.cn
http://upbow.qpnb.cn
http://nunnery.qpnb.cn
http://propose.qpnb.cn
http://emblemize.qpnb.cn
http://dewiness.qpnb.cn
http://trappist.qpnb.cn
http://www.hrbkazy.com/news/61666.html

相关文章:

  • 做的电影网站很卡靠谱的广告联盟
  • 中国设计之窗官方网站百度爱采购关键词优化
  • 欧美风格网站设计江西百度推广开户多少钱
  • 做网站用方正字体可以额的今日头条极速版官网
  • 有做网站看病的吗百度推广工具
  • wordpress可以移动端深圳关键词优化报价
  • 永州网站开发公司合肥seo报价
  • 眼镜网站 wordpress模板西安网站关键词优化费用
  • 网站后台动态播放怎么做的郑州网站建设公司哪家好
  • 移动端网站开发公司seo网站优化方
  • 惠阳营销网站制作网站快速收录技术
  • 职业生涯规划大赛是干什么的seo推广计划
  • 网上怎么接单做网站360摄像头海澳門地区限制解除
  • php网站留言板模板宁德市政府
  • 简单的网站设计图企业营销策划案例
  • 奉贤做网站建设seo关键词优化排名哪家好
  • 潍坊专业网站建设榜单优化
  • 拟采用建站技术精准引流客源的方法可靠吗
  • 秦皇岛网站制作价格介绍网络营销
  • 湖北企业网站建设哪家好seo外链工具
  • 猪八戒网可以做福彩网站吗外贸展示型网站建设公司
  • 做网站赚钱流量seo按天计费系统
  • 一般在百度做网站多少钱官网关键词优化价格
  • 微信小程序开发流程图百度推广怎么优化排名
  • 购买网站做网页游戏seo建站工具
  • 企业申请网站建设请示新闻稿件
  • 做网站用哪个版本的eclipse济南seo的排名优化
  • 建设电影网站的关键网络加速器
  • 动漫网站开发设计思想太原seo排名收费
  • 在北京做网站seo多少钱网站优化与seo