中国上市公司年报文本+爬虫代码(2000-2023年)

更新!2000-2023中国上市公司年报文本(爬虫代码+txt年报文本)

处理软件:Python 3.11

年度区间:2000-2023

年报数量:59160(其中包含2023年年报txt文件5185个

说明:本数据为2000-2023中国上市公司年报文本,已经从pdf转为txt格式,方便以本数据为起点进行文本分析及相关指标的构建。本数据特点如下:

(1)爬虫代码:提供详细的Python爬虫代码,方便大家学习掌握爬虫技术;

(2)文件格式:下载的pdf文件已经转化为txt格式,方便后续文本分析处理;

(3)文件过滤:pdf批量下载过程中存在年报更新的情况,已经对年报进行了筛选,剔除了非年报文件并保留了最新更新或更正的年报;

(4)文件名称:原始地址的文件名称并不统一,已经将年报文件名称进行了统一,统一格式为“股票代码_年度_发布日期_****年年度报告.txt”,例如,“000002_2023_20230331_2022年年度报告.txt”;

文件展示:

代码展示:

【下载→

方式一(推荐):主页个人 简介
经管数据库-CSDN博客

方式二:数据下载地址汇总-CSDN博客

首先,这个任务涉及到几个步骤:网络爬虫获取数据、文件转换、文本处理以及数据分析。由于这是一个复杂的请求,我会给出一个Python示例,利用BeautifulSoup库抓取网页,`pdfplumber`库转换PDF,`tabula-py`读取Excel,`python-docx`处理Word文档,`nltk`做关键词提取和计数,最后使用pandas存储结果。请注意,实际操作可能需要合法的API接口或者权限,这里仅作为演示: ```python import requests from bs4 import BeautifulSoup import pdfplumber import tabula from docx import Document import nltk from collections import Counter import pandas as pd # 网页抓取部分 def get_annual_report(url): response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # 这里假设年报链接都在soup里的某个class里,具体修改为实际页面结构 report_links = [link.get('href') for link in soup.find_all(class_='annual-report-link')] return report_links # 文件转换部分 def convert_to_txt(file_path, output_file): if file_path.endswith('.pdf'): with pdfplumber.open(file_path) as pdf: text = '\n'.join(pdf.pages.extract_text()) elif file_path.endswith(('.doc', '.docx')): doc = Document(file_path) text = '\n'.join([para.text for para in doc.paragraphs]) else: raise ValueError(f"Unsupported file format {file_path}") with open(output_file, 'w', encoding='utf-8') as f: f.write(text) # 数据分析部分 def extract_keywords_from_txt(txt_file, keyword_list): text = open(txt_file, 'r').read() word_freq = Counter(nltk.word_tokenize(text)) return word_freq # 示例URL和文件路径 url_example = "https://example.com/annual-reports" years = range(2006, 2024) stock_codes = ['SH600001'] # 某企业股票代码替换为实际值 output_excel = 'output.xlsx' # 主程序 reports = [] for code in stock_codes: for year in years: report_url = f"https://example.com/{code}-report-{year}" annual_report_links = get_annual_report(report_url) for link in annual_report_links: if 'doc' in link or 'pdf' in link: txt_file = 'temp.txt' convert_to_txt(link, txt_file) report_data = extract_keywords_from_txt(txt_file, keyword_list=['keyword1', 'keyword2']) # 根据需求替换关键词 reports.append((code, year, report_data)) df = pd.DataFrame(reports, columns=['股票代码', '份', '关键词词频']) df.to_excel(output_excel, index=False) ``` **
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值