def get_bs_for_1_stock(str_stock_code): # stock_list=readStockList.read_industry_stock_list_by_code(stock_code) # data = get_data(stock_list, '/stock/f10/balsheet.json?size=10000&page=1', '../data/bs_'+stock_id) str_response = xueqiu_base.get_response( 'https://stock.xueqiu.com/v5/stock/finance/cn/balance.json?symbol=' + str_stock_code + '&type=all&is_detail=true&count=10000') # write_f10_xls(1, data, '../data/bs_'+stock_id) json_data = json.loads(str_response) json_data = json_data['data'] if (('list' in json_data) & (json_data['list'] is not None)): json_list = json_data['list'] res_list = [] for item in json_list: res = {} for key in dict(item).keys(): if isinstance(item[key], list): res[key.replace('_', '')] = item[key][0] else: res[key.replace('_', '')] = item[key] res_list.append(res) str_list = json.dumps(res_list) df = pd.read_json(str_list, orient='records') df.to_excel( xueqiu_base.get_file_name('../data/bs/', 'bs_', str_stock_code))
def get_is_for_1_stock(str_stock_code): # stock_list=readStockList.read_industry_stock_list_by_code(stock_code) # data = get_data(stock_list, '/stock/f10/balsheet.json?size=10000&page=1', '../data/bs_'+stock_id) str_response=xueqiu_base.get_response('https://xueqiu.com/stock/f10/incstatement.json?size=10000&page=1&symbol='+str_stock_code) # write_f10_xls(1, data, '../data/bs_'+stock_id) json_data = json.loads(str_response) if (('list' in json_data) & (json_data['list'] is not None)): json_list = json_data['list'] str_list=json.dumps(json_list) df = pd.read_json(str_list, orient='records') df.to_excel(get_file_name(str_stock_code))
def get_is_for_1_stock_new(str_stock_code, country): url = 'https://stock.xueqiu.com/v5/stock/finance/' + country + '/income.json?type=all&is_detail=true&count=10000&symbol=' + str_stock_code print(url) str_response = xueqiu_base.get_response(url) # write_f10_xls(1, data, '../data/bs_'+stock_id) json_data = json.loads(str_response)['data'] if (('list' in json_data) & (json_data['list'] is not None)): json_list = json_data['list'] str_list = json.dumps(json_list) df = pd.read_json(str_list, orient='records') df.to_excel(get_file_name(str_stock_code))
def get_bs_for_1_stock(str_stock_code): # stock_list=readStockList.read_industry_stock_list_by_code(stock_code) # data = get_data(stock_list, '/stock/f10/balsheet.json?size=10000&page=1', '../data/bs_'+stock_id) str_response = xueqiu_base.get_response( 'https://stock.xueqiu.com/v5/stock/finance/cn/balance.json?symbol=' + str_stock_code + '&type=all&is_detail=true&count=10000') # write_f10_xls(1, data, '../data/bs_'+stock_id) json_data = json.loads(str_response) json_data = json_data['data'] if (('list' in json_data) & (json_data['list'] is not None)): json_list = json_data['list'] str_list = json.dumps(json_list) df = pd.read_json(str_list, orient='records') df.to_excel(get_file_name(str_stock_code))
def get_xueqiu_industry_quote(industry_df, file_name): # f = open(file_name + ".txt", "a", encoding='utf-8') headers = xueqiu_base.get_headers() # stock_list = readStockList.read_stock_list(sh_sz, range_start, range_end) print(industry_df) results = [] for index, row in industry_df.iterrows(): industry_code = row['industry2_code'] result = [industry_code] url = 'https://xueqiu.com/service/v5/stock/screener/quote/list?page=1&size=10000&order=desc&order_by=percent&exchange=CN&market=CN&ind_code=' + industry_code # url = 'https://xueqiu.com/industry/quote_order.json?page=1&size=10000&order=desc&exchange=CN&orderBy=percent&level2code='+industry_code print(url) # f.write(url) # f.write('\n') result.append(row['industry2_name']) result.append(url) # req = urllib.request.Request(url, headers=headers) # content = urllib.request.urlopen(req).read().decode('utf-8') # print(content) # f.write(content) # f.write('\n') # result.append(content) # results.append(result) str_response = xueqiu_base.get_response(url) # write_f10_xls(1, data, '../data/bs_'+stock_id) json_data = json.loads(str_response) json_data1 = json_data['data'] if (('list' in json_data1) & (json_data1['list'] is not None)): json_list = json_data1['list'] str_list = json.dumps(json_list) df = pd.read_json(str_list, orient='records') df['industry2_code'] = industry_code if index == 0: df_all = df else: df_all = df_all.append(df) df_all.to_excel(file_name + '.xlsx') # f.close() return results