自动提取公募基金定期报告中“投资策略和运作分析”部分全文,支持文本型和扫描版PDF的精准定位与汇总。
自动提取公募基金定期报告中"投资策略和运作分析"部分的全文。
如果不知道基金代码,需要先搜索:
python 基金报告提取.py --code 基金代码 --name "基金名称"
import akshare as ak
df = ak.fund_announcement_report_em(symbol='基金代码')
http://pdf.dfcfw.com/pdf/H2_{报告ID}_1.pdf
import fitz
import re
doc = fitz.open(stream=pdf_content, filetype='pdf')
full_text = ''
for page in doc:
html = page.get_text('html')
# 提取Unicode中文
codes = re.findall(r'&#x([0-9a-fA-F]+);', html)
for c in codes:
full_text += chr(int(c, 16))
import pdfplumber
with pdfplumber.open(pdf_file) as pdf:
all_text = ''
for page in pdf.pages:
text = page.extract_text()
if text:
all_text += text + '\n'
不同基金公司/报告类型关键词位置不同:
文本型PDF(景顺长城):
扫描版PDF(中泰星元):
# 提取投资策略部分
if '报告期内基金的投资策略和运作分析' in full_text:
idx1 = full_text.find('报告期内基金的投资策略和运作分析')
idx2 = full_text.find('报告期内基金的业绩表现', idx1)
if idx2 == -1:
idx2 = idx1 + 2500
content = full_text[idx1:idx2]
A: 使用pdfplumber替代PyMuPDF,并精确定位Page 7/8/9
A: 检查关键词是否有空格差异,尝试不同变体
A: 东方财富只保留最近4年报告,更早的报告需要其他渠道
A: 添加延时time.sleep(1-2),避免被限流
reports_{基金代码}/ - 原始报告文件{基金名称}_投资策略汇总.txt - 完整汇总pip install akshare pymupdf pdfplumber pandas requests
Created: 2026-03-08 Author: 有才
ZIP package — ready to use