当前位置:网站首页>码力十足学量化|如何在财务报告寻找合适的财务公告
码力十足学量化|如何在财务报告寻找合适的财务公告
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文本解析及筛选完毕!")
边栏推荐
- JMM详解
- [summary of knowledge points] chi square distribution, t distribution, F distribution
- [self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
- Dongle data collection
- Distributed lock implementation
- 伪装请求头库: anti-useragent
- JDBC connection pool
- 连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
- Solve the problem of garbled files uploaded by Kirin v10
- 【网络安全工具】USB控制软件有什么用
猜你喜欢

Distributed lock implementation
![Pit of kotlin bit operation (bytes[i] and 0xff error)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
Pit of kotlin bit operation (bytes[i] and 0xff error)

On siem

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

ManageEngine Zhuohao helps you comply with ISO 20000 standard (IV)

Excel visualization

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

让厦门灌口镇田头村变“甜头”村的特色农产品之一是

Teach you how to implement a deep learning framework

连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
随机推荐
Diffusion (multi-source search)
SQL语句
Solve the problem of garbled files uploaded by Kirin v10
async 与 await
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
Servlet
请求模块(requests)
[leetcode] day91- duplicate elements exist
Make: g++: command not found
HDU - 1501 Zipper(记忆化深搜)
Skywalking integrated Nacos dynamic configuration
端口扫描工具是什么?端口扫描工具有什么用
idea 好用插件汇总!!!
Transformer le village de tiantou en un village de betteraves sucrières
highmap gejson数据格式转换脚本
C语言课设工资管理系统(大作业)
记磁盘扇区损坏导致的Mysql故障排查
Factorial divisor (unique decomposition theorem)
Golang panic recover custom exception handling
golang panic recover自定义异常处理