Ejemplo n.º 1
0
def stock_zh_ah_spot() -> pd.DataFrame:
    """
    腾讯财经-港股-AH-实时行情
    https://stockapp.finance.qq.com/mstats/#mod=list&id=hk_ah&module=HK&type=AH&sort=3&page=3&max=20
    :return: 腾讯财经-港股-AH-实时行情
    :rtype: pandas.DataFrame
    """
    big_df = pd.DataFrame()
    page_count = _get_zh_stock_ah_page_count() + 1
    for i in tqdm(range(1, page_count)):
        hk_payload.update({"reqPage": i})
        res = requests.get(hk_url, params=hk_payload, headers=hk_headers)
        data_json = demjson.decode(
            res.text[res.text.find("{"):res.text.rfind("}") + 1])
        big_df = big_df.append(
            pd.DataFrame(data_json["data"]["page_data"]).iloc[:, 0].str.split(
                "~", expand=True),
            ignore_index=True,
        ).iloc[:, :-1]
    big_df.columns = [
        "代码",
        "名称",
        "最新价",
        "涨跌幅",
        "涨跌额",
        "买入",
        "卖出",
        "成交量",
        "成交额",
        "今开",
        "昨收",
        "最高",
        "最低",
    ]
    return big_df
Ejemplo n.º 2
0
def stock_zh_ah_name() -> dict:
    """
    腾讯财经-港股-AH-股票名称
    :return: 股票代码和股票名称的字典
    :rtype: dict
    """
    big_df = pd.DataFrame()
    page_count = _get_zh_stock_ah_page_count() + 1
    for i in tqdm(range(1, page_count)):
        hk_payload.update({"reqPage": i})
        res = requests.get(hk_url, params=hk_payload, headers=hk_headers)
        data_json = demjson.decode(
            res.text[res.text.find("{"):res.text.rfind("}") + 1])
        big_df = big_df.append(
            pd.DataFrame(data_json["data"]["page_data"]).iloc[:, 0].str.split(
                "~", expand=True),
            ignore_index=True,
        ).iloc[:, :-1]
    big_df.columns = [
        "代码",
        "名称",
        "最新价",
        "涨跌幅",
        "涨跌额",
        "买入",
        "卖出",
        "成交量",
        "成交额",
        "今开",
        "昨收",
        "最高",
        "最低",
    ]
    code_name_dict = dict(zip(big_df["代码"], big_df["名称"]))
    return code_name_dict
def stock_zh_ah_spot():
    big_df = pd.DataFrame()
    page_count = get_zh_stock_ah_page_count() + 1
    for i in range(1, page_count):
        hk_payload.update({"reqPage": i})
        res = requests.get(hk_url, params=hk_payload, headers=hk_headers)
        data_json = demjson.decode(res.text[res.text.find("{"): res.text.rfind("}") + 1])
        big_df = big_df.append(pd.DataFrame(data_json["data"]["page_data"]).iloc[:, 0].str.split("~", expand=True), ignore_index=True)
    big_df.columns = ["代码", "名称", "最新价", "涨跌幅", "涨跌额", "买入", "卖出", "成交量", "成交额", "今开", "昨收", "最高", "最低"]
    return big_df