pywencai
获取同花顺问财数据
⚠️注意:由于问财登录策略调整,目前必填cookie参数才能使用,可以参看下面关于如何获取cookie参数的介绍
环境依赖
由于程序中执行了js代码,请先保证已安装了Node.js,需要版本v16+
未安装请自行安装
安装
pip install pywencai
由于问财接口策略经常发生变化,请安装最新版本使用,遇到问题时,优先尝试升级解决
视频教程
Demo
import pywencai
res = pywencai.get(query='退市股票', sort_key='退市@退市日期', sort_order='asc', cookie='xxx')
print(res)
API
get(**kwargs)
根据问财语句查询结果
参数
query
必填,查询问句
老版本的question参数1.0版本以后会弃用,请以后统一使用query参数
sort_key
非必填,指定用于排序的字段,值为返回结果的列名
sort_order
非必填,排序规则,至为asc(升序)或desc(降序)
page
非必填,查询的页号,默认为1
perpage
非必填,每页数据条数,默认值100,由于问财做了数据限制,最大值为100,指定大于100的数值无效。
loop
非必填,是否循环分页,返回多页合并数据。默认值为False,可以设置为True或具体数值。
当设置为True时,程序会一直循环到最后一页,返回全部数据。
当设置具体数值n时,循环请求n页,返回n页合并数据。
query_type
非必填,默认为stock,当查询的类型不是股票的时候需要传,取值如下:
| 取值 | 含义 |
|---|---|
| stock | 股票 |
| zhishu | 指数 |
| fund | 基金 |
| hkstock | 港股 |
| usstock | 美股 |
| threeboard | 新三板 |
| conbond | 可转债 |
| insurance | 保险 |
| futures | 期货 |
| lccp | 理财 |
| foreign_exchange | 外汇 |
retry
非必填,默认为10,表示请求失败后的重试次数。
sleep
非必填,默认为0,表示循环请求时,每次请求间隔多少秒。
log
非必填,默认为False,是否在控制台打印日志。
pro
非必填,默认为False,付费版传True,
必须传入cookie参数才能使用付费版
cookie
必填,默认为None
pywencai.get(question='近3个月每日市盈率', pro=True, cookie='xxxx')
cookie获取方法,复制请求头中的Cookie字段值
request_params
非必填,默认为{},可以设置额外的request参数
pywencai.get(query='昨日涨幅', sort_order='asc', loop=True, log=True, request_params={ 'proxies': proxies })
具体参数参看:https://requests.readthedocs.io/en/latest/api/#requests.request
no_detail
非必填,默认为False,当为True时,查询一些详情类问题不再会返回字典,而返回None,可以保证查询结果类型一直为pd.DataFrame或None。
find
非必填,默认为None,可以传一个数组,例如['600519', '000010'],数组内的对应标的会排列在DataFrame的最前面。
【注意】 1、该参数只有结果范围DataFrame时有效。2、配置该参数后,loop参数会失效,结果只会返回前100条。
user_agent
非必填,默认为None,可以自己传user_agent,不使用随机的生成的user_agent
返回值
当查询的是列表时,该方法返回一个pandas的Dataframe
当查询的是详情时,该方法返回一个字典,字典中可能包含若干个文本和Dataframe
Metadata
Release files for pywencai 0.13.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pywencai-0.13.1.tar.gz | 903.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pywencai-0.13.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.8 MB
Release files / pywencai-0.13.1.tar.gz
| Download URL | pywencai-0.13.1.tar.gz |
|---|---|
| Size | 903.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a127fe3c5a818e1d2f428c9c3ffb42ed19aa4282e2b475ca0b2bf5b90aa72814
|
|
BLAKE2b-256 checksum How to use checksums |
86c019750adb57c48c8cc95a5c78a08b4e230f5e9302904c35b0ef3197bf098e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Release files / pywencai-0.13.1-py3-none-any.whl
| Download URL | pywencai-0.13.1-py3-none-any.whl |
|---|---|
| Size | 911.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6786a014baed92cef25d855f8f175c5265868552dfacd7e37c098f92e4e038ff
|
|
BLAKE2b-256 checksum How to use checksums |
c7716fa9606a3c042e59f8020914e59d4d4919100e0cd53697d7e2a677f70835
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Security for pywencai 0.13.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.