Article Directory
foreword
I wrote a blog post before to introduce how to obtain market data and other data through various packages. Today we will expand the data of a snowball. Snowball website https://xueqiu.com/ .
Pre-blog post portal: [How much do you know about data] A literature understands to obtain stock market data (including codes) through Tushare, AKshare, baostock, Ashare, Pytdx https://blog.csdn.net/popboy29/article/details/125815775
提示:以下是本篇文章正文内容,下面案例可供参考
1. What are snowballs and pysnowball?
Snowball (Snowball / Xueqiu) is a vertical social media for investors established in March 2010. Users can pay attention to securities codes such as stocks and funds on Snowball, and check the real-time market conditions of Shanghai, Shenzhen, Hong Kong, and US stocks; Exchange investment insights with similar investors; create and share personal investment portfolios; create Shanghai, Shenzhen and US stock stock accounts, fund trading accounts, and buy and sell stocks and funds on a firm basis.
pysnowball is the Snowball APP Python API. Before calling the API, you need to manually obtain the token of the Snowball website. Use set_token to set the token before you can access the Snowball API. There is an introduction on the Internet to check the browser cookie by pressing F12, but it is too troublesome to do this every time. For the convenience of operation, here we introduce the browser_cookie3 library. After the Edge browser logs in, the corresponding cookie will be generated. After reading it with browser_cookie3, you can directly access it.
2. How to use
1. Import the pysnowball library
The pysnowball API interface has the following functions. For specific usage methods, please visit
https://gitee.com/wanghuan1989/pysnowball
- Real-time market
- Real-time stroke
- performance forecast
- Agency Rating
- Fund Flow Trend
- Fund Flow History
- Fund transaction distribution
- Large transactions
- Margin financing
- performance indicators
- income statement
- balance sheet
- cash flow statement
- Main business structure
- F10 Top Ten Shareholders
- F10 main indicators
- F10 Number of shareholders
- F10 Institutional Positions
- F10 dividend financing
- F10 industry comparison
Install pysnowball
pip install pysnowball
2. Import browser_cookie3 library
browser_cookie3 can read cookies already cached by computer browsers (such as Chrome Firefox Opera Edge Chromium Brave). Install it before use, which is convenient for later operation. Of course, you can do it manually, or you don’t need this library. However, for the convenience of use, it is recommended to install it. After all, it is troublesome to log in and extract cookies manually every day.
pip install browser-cookie3
3. Demo code (need to use the edge browser to log in to the Xueqiu website https://xueqiu.com/ in advance )
The code is as follows (example):
import pysnowball as xq
import browser_cookie3
def get_cookie_xq():
cookies = browser_cookie3.edge(domain_name='xueqiu.com')
# print('cookies',cookies)
xq_a_token = ''
for item in cookies:
# print('%s = %s' % (item.name, item.value))
if item.name == "xq_a_token" :
xq_a_token = 'xq_a_token=' + item.value + ';'
return xq_a_token
def json_print(_dict):
# json 格式化打印
import json
print(json.dumps(_dict, indent=2,ensure_ascii=False)) # r.json()是json对象,indent表示缩进,ensure_ascii设置编码
if __name__ == "__main__":
xq.set_token(get_cookie_xq())
ret = xq.quote_detail(symbol="SH600259")
# print(ret)
json_print(ret)
ret = xq.quotec('SZ300750')
# print(ret)
json_print(ret)
Summarize
This article just demonstrates how to easily use python to obtain snowball website data. For more specific data APIs, please explore by yourself.