原创 +1银贝 [数据篇]爬取东方财富分析师数据

小小的夏天 2023-8-23 302

一、前言

研究分析师策略时,想从网上找分析师数据以方便实盘,这个分析师数据要比新浪的分析师数据更加全面,这次爬取用到异步爬取,爬取速度极快,一千多页原本要40分钟现在几十秒即可爬完。爬取这个数据时消耗我很大的精力去修改和优化,而且是17年到现在的数据,比网页的数据时间跨度更广。

东方财富分析师数据网址:https://data.eastmoney.com/report/stock.jshtml

二、代码

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import pandas as pd
import time, aiohttp, asyncio
pd.set_option('max_rows', None)
pd.set_option('max_columns', None)
pd.set_option('expand_frame_repr', False)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
import datetime as dt

date_start = '2017-01-01'  # 数据开始时间
date_mid = '2023-01-01'  # 数据的中间

date_mid2 = dt.datetime.strptime(date_mid, '%Y-%m-%d')  # 将日期字符串转换为datetime对象
date_mid_plus_one = date_mid2 + dt.timedelta(days=1)  # 在日期上加1天
date_mid_plus_one = date_mid_plus_one.strftime('%Y-%m-%d')  # 在日期上加1天,不然数据合并时,数据重复

date_end = str(dt.date.today())  # 当天时间
max_page = 1386  # 最大页数

# df股票代码添加前缀
def change_df_code(df):
    new = []
    for df_code in df['股票代码']:
        if df_code.startswith('6'):
            new.append('sh' + df_code)
        elif df_code.startswith('8') or df_code.startswith('4

本主题为课程学员专享,成为股票量化投资课程学员后可免费阅读

成为学员
最新回复 ( 0条评论 )


官方微信
码力十足学量化
Powered by Xiuno BBS 4.0.7

官方微信