当前位置:网站首页>码力十足学量化|如何在财务报告寻找合适的财务公告
码力十足学量化|如何在财务报告寻找合适的财务公告
2022-07-01 06:18:00 【码力十足学量化】
做投资,我们经常要阅读公告,如何对公告进行解读呢?本文将遍历一个文件夹里的所有的理财公告
PDF文件,通过PDF文本解析对理财公告进行深度筛选,获取符合要求的公告内容。
1.首先遍历文件夹里所有的PDF文件,拼接出需要的pdf的文件位置。然后把他们放在一个列表里面,方便之后调用。
import os
import pdfplumber
path= r"C:\Users\86186\PycharmProjects\online\spider\requests\财务报表" # 财务报表储存路径
# 寻找文件夹下所有pdf文件路径
file_list=[]
for files in os.walk(path): # 遍历路径下所有文件夹
for file in files[2]: # 遍历路径下所有文件
if os.path.splitext(file)[1]=='.pdf' or os.path.splitext(file)[1]=='.PDF': # 检查文件后缀名
file_list.append(path+"\\"+file) # 拼接文件路径
print(file_list)
2.遍历所有pdf里面的内容,然后用pdfplumber函数获取文本里面的内容,将所有的文本内容拼接到一起。
# PDF文本解析和筛选出正文中的内容
pdf_all=[]
for i in range(len(file_list)):
pdf=pdfplumber.open(file_list[i]) # 打开每个pdf文件
pages=pdf.pages
text_all=[]
for page in pages: # 遍历每一页的信息
text=page.extract_text() # 提取当前页的文本内容
text_all.append(text) # 将每一页的内容汇集到一起
text_all="".join(text_all) # 把列表转换为字符串
pdf.close()
3.对遍历后得到的文本内容进行分析,这里写的关键字筛选,只有当PDF文件里含有“自有”,“议案”,“理财”和“现金管理”
,将这些文件筛选出来。这里大家可以通过自然语言和机器学习来进行更有深度的分析。
if ("增持"in text_all) or ("现金管理" in text_all) or ("理财" in text_all):
pdf_all.append(file_list[i])
print(pdf_all) # 打印筛选出的pdf文件
4.筛选出来后,将筛选出来的PDF文件执行移动操作,创建一个新的文件路径,然后将筛选出来的PDF文件移动到新的文件夹里。
# 移动筛选后pdf文件
for pdf_i in pdf_all:
new_path=r"C:\\Users\\86186\\PycharmProjects\\online\\spider\\requests\\筛选后的文件夹\\"+pdf_i.split('\\')[-1]
os.rename(pdf_i,new_path) # 执行文件的移动操作
print("PDF文本解析及筛选完毕!")
5.完成代码
import os
import pdfplumber
path= r"C:\Users\86186\PycharmProjects\online\spider\requests\财务报表" # 财务报表储存路径
# 寻找文件夹下所有pdf文件路径
file_list=[]
for files in os.walk(path): # 遍历路径下所有文件夹
for file in files[2]: # 遍历路径下所有文件
if os.path.splitext(file)[1]=='.pdf' or os.path.splitext(file)[1]=='.PDF': # 检查文件后缀名
file_list.append(path+"\\"+file) # 拼接文件路径
print(file_list)
# PDF文本解析和筛选出正文中的内容
pdf_all=[]
for i in range(len(file_list)):
pdf=pdfplumber.open(file_list[i]) # 打开每个pdf文件
pages=pdf.pages
text_all=[]
for page in pages: # 遍历每一页的信息
text=page.extract_text() # 提取当前页的文本内容
text_all.append(text) # 将每一页的内容汇集到一起
text_all="".join(text_all) # 把列表转换为字符串
pdf.close()
# 筛选正文中的内容
if ("增持"in text_all) or ("现金管理" in text_all) or ("理财" in text_all):
pdf_all.append(file_list[i])
print(pdf_all) # 打印筛选出的pdf文件
# 移动筛选后pdf文件
for pdf_i in pdf_all:
new_path=r"C:\\Users\\86186\\PycharmProjects\\online\\spider\\requests\\筛选后的文件夹\\"+pdf_i.split('\\')[-1]
os.rename(pdf_i,new_path) # 执行文件的移动操作
print("PDF文本解析及筛选完毕!")
边栏推荐
- MySQL中 in 和 exists 的区别
- 【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
- 分布式锁实现
- SystemVerilog learning-09-interprocess synchronization, communication and virtual methods
- Factorial divisor (unique decomposition theorem)
- three.js小结
- Golang panic recover custom exception handling
- C语言课设职工信息管理系统(大作业)
- FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
- SystemVerilog learning-08-random constraints and thread control
猜你喜欢

DHT11 temperature and humidity sensor

手把手教你实现一个深度学习框架...

How did ManageEngine Zhuohao achieve the goal of being selected into Gartner Magic Quadrant for four consecutive years?

C# ManualResetEvent 类的理解

高阶-二叉平衡树

Understanding of C manualresetevent class

自开发软件NoiseCreater1.1版本免费试用

讓田頭村變甜頭村的特色農產品是仙景芋還是白菜

MongoDB:一、MongoDB是什么?MongoDB的优缺点

JDBC database operation
随机推荐
阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]
连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
Linux closes the redis process SYSTEMd+
lxml模块(数据提取)
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
地宫取宝(记忆化深搜)
交换机配置软件具有的作用
On siem
How does MySQL store Emoji?
Servlet
68 cesium code datasource loading czml
One of the characteristic agricultural products that make Tiantou village, Guankou Town, Xiamen into a "sweet" village is
DHT11 temperature and humidity sensor
B-tree series
webapck打包原理--启动过程分析
地宮取寶(記憶化深搜)
golang panic recover自定义异常处理
Transformer le village de tiantou en un village de betteraves sucrières
highmap gejson数据格式转换脚本