Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

recommend: 希望有一个单一功能的查询接口 #10

Closed
GXY2017 opened this issue Apr 28, 2021 · 4 comments
Closed

recommend: 希望有一个单一功能的查询接口 #10

GXY2017 opened this issue Apr 28, 2021 · 4 comments

Comments

@GXY2017
Copy link

GXY2017 commented Apr 28, 2021

r = wc.get_strategy() 会返回一个策略选股表,但其中无法查询所属行业、概念、首次涨停时间、最终涨停时间等信息。
建议有如下查询功能:

wc.query(w= r"上一交易日没有涨停;市值大于100亿;今日涨停时间", 
fields=["涨停时间",“总市值”])-> pd.DataFrame,   
@GraySilver
Copy link
Owner

这提议挺好,我先看下接口是否返回其中相关内容

@GXY2017
Copy link
Author

GXY2017 commented May 15, 2021

网页get-robot-data中的cookies 需要 hexin_v,hexin_v每天更新,需要在本地自动生成。https://blog.csdn.net/weixin_41406913/article/details/103280900 提供了一个方法。

@Lance-Mao
Copy link

这提议挺好,我先看下接口是否返回其中相关内容

作者,请问这个好实现不,我感觉有点困难,捣鼓了好久没结果

@GXY2017
Copy link
Author

GXY2017 commented Aug 9, 2021

  1. 安装execjs
    import execjs
  2. 把附件TXT改成 *.js, 放在程序目录下。
  3. 复制下面两个函数。

    def __wencaiHexinV(self):
        """
        js加密信息,每次查询都不一样。
        重点参考:https://blog.csdn.net/weixin_41406913/article/details/103280900
        :param hexin_v: 在get-robot-data中找到。
        :return:
        """
        with open('./xuangu.js', 'r') as f:
            jscontent = f.read()
        context = execjs.compile(jscontent)

        return context.call("v")

    def WenCaiResult(self, querystr):
        url = r'http://www.iwencai.com/unifiedwap/unified-wap/v2/result/get-robot-data?'
        headers = {
            'Cookie': "",
            "Referer": "http://www.iwencai.com/stockpick?tid=stockpick",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"
        }
        formdata = {"secondary_intent": "stock",
                    "perpage": 500,
                    "page": 1,
                    "block_list": "",
                    "source": "Ths_iwencai_Xuangu",
                    "version": 2.0,
                    "question": querystr,
                    }
        # headers['cookie'] = 'v={}'.format(hexin_v)  # 如果网站修改了,此处手工输入 hexin_v
        headers['cookie'] = 'v={}'.format(self.__wencaiHexinV())

        count = 0
        while count <= 10:
            try:
                res = requests.post(headers=headers, url=url, data=formdata, timeout=(5, 10))  # connect and read timeout
                time.sleep(0.3)
                if res.status_code != 200:
                    print(res.status_code)
                    count = count + 1
                    time.sleep(random.randint(1, 5))
                    pass
                else:
                    info = json.loads(res.text)
                    if 'data' in info:
                        datalst = info['data']['answer'][0]["txt"][0]["content"]["components"][0]["data"]["datas"]
                        # print(datalst)
                        return info, datalst
                    else:
                        print("No info['data']")
                        return None, None
            except:
                pass
        else:
            return print("访问次数过多,去网页输入验证码。")

xuangu.txt

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants