本文主要是介绍【大麦小米学量化】升级pywencai解决同花顺问财接口访问问题实现智能选股(小白避坑指南),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 前言
- 一、pywencai 怎么了?
- 二、解决办法
- 三、智能选股代码(缺环境的,请看开头文章推荐的博文)
- 总结
前言
前面撰文:【大麦小米学量化】通过pywencai访问同花顺问财接口实现智能选股
很多小伙伴应该已经用得很六了。但最近出了点小问题?解决后发出来,希望可以帮到大家。
一、pywencai 怎么了?
最近运行pywencai ,总是报错,同样的程序,怎么就报错了呢?
print后显示如下:
pywencai {'请填写主题': '<p>为你从5340只个股中找到<strong><span style="color:#ff2346">1644</span></strong>只符合条件的A 股,具体如下:</p>', 'xuangu_tableV1': code 股票简称 最新价 最新涨跌幅 区间涨跌幅:前复权[19901220-20240104] 涨跌幅:前复权[20240110] market_code 交易状态[20240110] 股票代码
0 000156 华数传媒 7.21 -1.905 -44.240287 -1.905 33 交易 000156
1 000166 申万宏源 4.25 0.236 -65.395860 0.236 33 交易 000166
2 000068 华控赛格 3.57 0.000 -20.168428 0.000 33 交易 000068
3 000701 厦门信达 5.24 -0.758 -19.297563 -0.758 33 交易 000701
4 000727 冠捷科技 2.39 -1.240 -3.524553 -1.240 33 交易 000727
5 000702 正虹科技 6.15 0.163 -6.225380 0.163 33 交易 000702
6 000931 中关村 5.77 -0.517 -81.249059 -0.517 33 交易 000931
7 000751 锌业股份 3.22 0.000 -2.091508 0.000 33 交易 000751
8 000809 铁岭新城 3.10 -0.641 -14.082873 -0.641 33 交易 000809
9 000882 华联股份 1.69 1.198 -41.354489 1.198 33 交易 000882, 'container': {'btn1': q ... url
0 非st;非停牌;4天前持续跌; ... https://search.10jqka.com.cn/unifiedmobile/?sh...[1 rows x 6 columns]}, '问财选A股': q ... url
0 非st;非停牌;4天前持续跌; ... https://search.10jqka.com.cn/unifiedmobile/?sh...
二、解决办法
通过增加各种筛选条件,过滤结果,总是不尽人意。突然想到,是不是该升级一下库了?
pip install pywencai -U
(base) C:\Users\Administrator>pip install pywencai -U
Requirement already satisfied: pywencai in d:\programdata\anaconda3\lib\site-packages (0.12.0)
Collecting pywencaiDownloading pywencai-0.12.2-py3-none-any.whl.metadata (4.7 kB)
Requirement already satisfied: PyExecJS<2.0.0,>=1.5.1 in d:\programdata\anaconda3\lib\site-packages (from pywencai) (1.5.1)
Requirement already satisfied: fake-useragent<2.0.0,>=1.1.1 in d:\programdata\anaconda3\lib\site-packages (from pywencai) (1.1.1)
Requirement already satisfied: pandas<3.0.0,>=1.5.0 in c:\users\administrator\appdata\roaming\python\python310\site-packages (from pywencai) (1.5.3)
Requirement already satisfied: pydash<8.0.0,>=7.0.3 in d:\programdata\anaconda3\lib\site-packages (from pywencai) (7.0.6)
Requirement already satisfied: requests in d:\programdata\anaconda3\lib\site-packages (from pywencai) (2.28.2)
Requirement already satisfied: python-dateutil>=2.8.1 in d:\programdata\anaconda3\lib\site-packages (from pandas<3.0.0,>=1.5.0->pywencai) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in d:\programdata\anaconda3\lib\site-packages (from pandas<3.0.0,>=1.5.0->pywencai) (2022.7)
Requirement already satisfied: numpy>=1.21.0 in d:\programdata\anaconda3\lib\site-packages (from pandas<3.0.0,>=1.5.0->pywencai) (1.23.5)
Requirement already satisfied: typing-extensions!=4.6.0,>=3.10 in d:\programdata\anaconda3\lib\site-packages (from pydash<8.0.0,>=7.0.3->pywencai) (4.4.0)
Requirement already satisfied: six>=1.10.0 in d:\programdata\anaconda3\lib\site-packages (from PyExecJS<2.0.0,>=1.5.1->pywencai) (1.16.0)
Requirement already satisfied: charset-normalizer<4,>=2 in d:\programdata\anaconda3\lib\site-packages (from requests->pywencai) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in d:\programdata\anaconda3\lib\site-packages (from requests->pywencai) (3.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\programdata\anaconda3\lib\site-packages (from requests->pywencai) (1.26.14)
Requirement already satisfied: certifi>=2017.4.17 in d:\programdata\anaconda3\lib\site-packages (from requests->pywencai) (2022.12.7)
Downloading pywencai-0.12.2-py3-none-any.whl (911 kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 911.1/911.1 kB 800.8 kB/s eta 0:00:00
Installing collected packages: pywencaiAttempting uninstall: pywencaiFound existing installation: pywencai 0.12.0Uninstalling pywencai-0.12.0:Successfully uninstalled pywencai-0.12.0
Successfully installed pywencai-0.12.2(base) C:\Users\Administrator>
果然从0.12.0升级到0.12.2,再次运行以下选股代码,一切OK。
三、智能选股代码(缺环境的,请看开头文章推荐的博文)
# -*- coding: utf-8 -*-
import pywencai
def xg_wencai(query,perpage=200,ret='df'):# ret为code返回六位代码,symbol则为'代码.市场'格式,默认返回dfdf = pywencai.get(query=query, sort_key='股票代码', sort_order='asc', perpage=perpage, )if df is None:return Noneelif df.empty:return Noneelse:if ret == 'symbol':return df['股票代码'].tolist()elif ret == 'code':return df['股票代码'].str[:6].tolist()else:return df.round(3)if __name__ == '__main__':query = '非st;非停牌;连续3天涨幅介于1%-4%;股价大于60日均线;无长上影线;'fav_list = xg_wencai(query,perpage=200,ret='symbol')print(fav_list)
总结
以后库报错了,很有可能是系统有调整,先来一个 -U 升级一下。也许作者已经解决了,个人就别瞎折腾了。
这篇关于【大麦小米学量化】升级pywencai解决同花顺问财接口访问问题实现智能选股(小白避坑指南)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!