def sw_index_spot() -> pd.DataFrame: """ 申万一级行业-实时行情数据 http://www.swsindex.com/idx0120.aspx?columnid=8832 :return: 申万一级行业实时行情数据 :rtype: pandas.DataFrame """ url = "http://www.swsindex.com/handler.aspx" result = [] for i in range(1, 3): payload = sw_payload.copy() payload.update({"p": i}) payload.update({"timed": int(time.time() * 1000)}) r = requests.post(url, headers=sw_headers, data=payload) data = r.content.decode() data = data.replace("'", '"') data = json.loads(data) result.extend(data["root"]) temp_df = pd.DataFrame(result) temp_df["L2"] = temp_df["L2"].str.strip() temp_df.columns = ["指数代码", "指数名称", "昨收盘", "今开盘", "成交额", "最高价", "最低价", "最新价", "成交量"] temp_df["昨收盘"] = pd.to_numeric(temp_df["昨收盘"]) temp_df["今开盘"] = pd.to_numeric(temp_df["今开盘"]) temp_df["成交额"] = pd.to_numeric(temp_df["成交额"]) temp_df["最高价"] = pd.to_numeric(temp_df["最高价"]) temp_df["最低价"] = pd.to_numeric(temp_df["最低价"]) temp_df["最新价"] = pd.to_numeric(temp_df["最新价"]) temp_df["成交量"] = pd.to_numeric(temp_df["成交量"]) return temp_df
def sw_index_spot(): result = [] for i in range(1, 3): payload = sw_payload.copy() payload.update({"p": i}) payload.update({"timed": int(time.time() * 1000)}) req = requests.post(sw_url, headers=sw_headers, data=payload) data = req.content.decode() data = data.replace("'", '"') data = json.loads(data) result.extend(data["root"]) result = pd.DataFrame(result) result["L2"] = result["L2"].str.strip() result.columns = ["指数代码", "指数名称", "昨收盘", "今开盘", "成交额", "最高价", "最低价", "最新价", "成交量"] return result