吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 9388|回复: 88
上一主题 下一主题
收起左侧

[Python 原创] 获取东方财富网股票的实时数据,所有股票的数据

    [复制链接]
跳转到指定楼层
楼主
在外DE孩子 发表于 2024-5-30 22:31 回帖奖励
需要安装python

通过访问东方财富网的连接:http://82.push2.eastmoney.com/api/qt/clist/get

可以运行python文件获取:【序号,代码,名称,最新价,涨跌幅,涨跌额,成交量,成交额,振幅,最高,最低,今开,昨收,量比,换手率,市盈率-动态,市净率,总市值,流通市值,涨速,5分钟涨跌,60日涨跌幅,年初至今涨跌幅,】

如果你正好在关注股票也需要实时信息,可以直接运行程序即可,可以将数据下载到本地文件夹下。

如有问题欢迎留言评论

如果觉得有用,还请动动发财小手给个评分,谢谢

[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import pandas as pd
import requests
from datetime  import datetime
import time
import numpy as np
# from crazy import *
# dataframe_completely_display(100,100)
def stock_zh_a_spot_em() -> pd.DataFrame:
    """
    东方财富网-沪深京 A 股-实时行情
    https://quote.eastmoney.com/center/gridlist.html#hs_a_board
    :return: 实时行情
    :rtype: pandas.DataFrame
    """
    url = "http://82.push2.eastmoney.com/api/qt/clist/get"
    params = {
        "pn": "1",
        "pz": "50000",
        "po": "1",
        "np": "1",
        "ut": "bd1d9ddb04089700cf9c27f6f7426281",
        "fltt": "2",
        "invt": "2",
        "fid": "f3",
        "fs": "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048",
        "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
        "_": "1623833739532",
    }
    r = requests.get(url, params=params)
    data_json = r.json()
    if not data_json["data"]["diff"]:
        return pd.DataFrame()
    temp_df = pd.DataFrame(data_json["data"]["diff"])
    temp_df.columns = [
        "_",
        "最新价",
        "涨跌幅",
        "涨跌额",
        "成交量",
        "成交额",
        "振幅",
        "换手率",
        "市盈率-动态",
        "量比",
        "5分钟涨跌",
        "代码",
        "_",
        "名称",
        "最高",
        "最低",
        "今开",
        "昨收",
        "总市值",
        "流通市值",
        "涨速",
        "市净率",
        "60日涨跌幅",
        "年初至今涨跌幅",
        "-",
        "-",
        "-",
        "-",
        "-",
        "-",
        "-",
    ]
    temp_df.reset_index(inplace=True)
    temp_df["index"] = temp_df.index + 1
    temp_df.rename(columns={"index": "序号"}, inplace=True)
    temp_df = temp_df[
        [
            "序号",
            "代码",
            "名称",
            "最新价",
            "涨跌幅",
            "涨跌额",
            "成交量",
            "成交额",
            "振幅",
            "最高",
            "最低",
            "今开",
            "昨收",
            "量比",
            "换手率",
            "市盈率-动态",
            "市净率",
            "总市值",
            "流通市值",
            "涨速",
            "5分钟涨跌",
            "60日涨跌幅",
            "年初至今涨跌幅",
        ]
    ]
    temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
    temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
    temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
    temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
    temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
    temp_df["振幅"] = pd.to_numeric(temp_df["振幅"], errors="coerce")
    temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
    temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
    temp_df["今开"] = pd.to_numeric(temp_df["今开"], errors="coerce")
    temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce")
    temp_df["量比"] = pd.to_numeric(temp_df["量比"], errors="coerce")
    temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
    temp_df["市盈率-动态"] = pd.to_numeric(temp_df["市盈率-动态"], errors="coerce")
    temp_df["市净率"] = pd.to_numeric(temp_df["市净率"], errors="coerce")
    temp_df["总市值"] = pd.to_numeric(temp_df["总市值"], errors="coerce")
    temp_df["流通市值"] = pd.to_numeric(temp_df["流通市值"], errors="coerce")
    temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
    temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
    temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
    temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
    return temp_df
def update_array(arr, value):
    """
    序列迭代更新,随着一个一个新的数据插入到最后面,前面第一个就给删掉,依次迭代
    """
    arr[:-1] = arr[1:]
    arr[-1] = value
    return arr
df = stock_zh_a_spot_em()
yest_price = dict(zip(df['代码'], df['昨收']))
 
print(df)
 
label = str(int(time.time()))
 
df.to_excel(f'data01-{label}.xlsx',index=False)

免费评分

参与人数 16吾爱币 +14 热心值 +14 收起 理由
btsun + 1 + 1 我很赞同!
Elowen1127 + 1 谢谢@Thanks!
不如相忘于江湖 + 1 谢谢@Thanks!
kseleven + 1 我很赞同!
iamlee + 1 + 1 用心讨论,共获提升!
ddly357 + 1 + 1 我很赞同!
qyfs2006 + 1 + 1 谢谢@Thanks!
luolifu + 1 + 1 我很赞同!
52pojie886 + 1 + 1 dalao niub
ywsyer5621 + 1 + 1 我很赞同!
Diamondzl + 1 + 1 谢谢@Thanks!
从白嫖到不嫖 + 1 + 1 谢谢@Thanks!
junjia215 + 1 + 1 用心讨论,共获提升!
timeni + 1 + 1 用心讨论,共获提升!
jsxz445665 + 1 + 1 我很赞同!
Rockyking + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
 楼主| 在外DE孩子 发表于 2024-5-31 08:56 |楼主
StockGeek 发表于 2024-5-30 22:54
太泛滥会不会像新浪一样,直接堵了

应该不会吧,现在还可以用,堵了来找我,哈哈,方法都一样
推荐
我爱52我爱 发表于 2024-5-30 22:45
4#
StockGeek 发表于 2024-5-30 22:54
5#
你好,再见 发表于 2024-5-30 23:26
请问一下这个接口有速率限制吗
6#
700529yrf 发表于 2024-5-31 06:38
能集成到炒股软件里就更好了
7#
yk2014 发表于 2024-5-31 08:44
StockGeek 发表于 2024-5-30 22:54
太泛滥会不会像新浪一样,直接堵了

新浪堵了吗,我偶尔还在用
8#
5151diy 发表于 2024-5-31 08:45
感谢楼主提供爬取数据程序
9#
5196 发表于 2024-5-31 08:51
看来神车可以换了
10#
lzmomo 发表于 2024-5-31 08:54
很厉害呀,要是多一些注释就好了。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-30 20:10

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表