1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Python获取 获取全部基金信息 天天基金网 东方财富 基金排行

Python获取 获取全部基金信息 天天基金网 东方财富 基金排行

时间:2021-11-12 05:18:11

相关推荐

Python获取 获取全部基金信息 天天基金网 东方财富 基金排行

Python获取 获取全部基金信息 天天基金网 东方财富 基金排行

通过URL获取基金信息,然后切割成list的list,然后转换成表

def get_fund_data():""" 获取天天基金,8千多基金排行(默认为近6个月收益率)"""header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36','Referer': '/data/fundranking.html','Cookie': 'st_si=51694067779834; st_asi=delete; _SessionId=e1pno0koqkcp5es3xyzyrg1n; EMFUND1=null; EMFUND2=null; EMFUND3=null; EMFUND4=null; EMFUND5=null; EMFUND6=null; EMFUND7=null; EMFUND8=null; EMFUND0=null; _adsame_fullscreen_18503=1; EMFUND9=09-23 01:16:38@#$%u4E07%u5BB6%u65B0%u5229%u7075%u6D3B%u914D%u7F6E%u6DF7%u5408@%23%24519191; st_pvi=87492384111747; st_sp=-09-23%2000%3A05%3A17; st_inirUrl=http%3A%2F%%2Fdata%2Ffundranking.html; st_sn=15; st_psi=0923011636912-0-9218336114'}url2 = '/data/rankhandler.aspx?op=ph&dt=kf&ft=all&rs=&gs=0&sc=6yzf&st=desc&sd=-01-01&ed=-12-31&qdii=&tabSubtype=,,,,,&pi=1&pn=10000&dx=1&v=0.891085836641'response = requests.get(url2, headers=header)text = response.textcompile_data = "[" + re.findall("\\[(.*)\\]", str(text))[0] + "]"strip_data = str(compile_data).strip('[').strip(']').replace(" ", "")column_list = ["基金代码", "基金简称", "基金条码", "日期", "单位净值", "累计净值", "日增长率", "近1周增长率", "近1月增长率", "近3月", "近半年", "近1年", "近2年", "近3年", "今年来", "成立来", "成立日", "其他2", "其他3", "最高申购费率", "优惠费率", "其他6", "其他7", "其他8", "其他9"]list_list = [i.strip('"').split(",") for i in strip_data.split('","')]df = pd.DataFrame(list_list, columns=column_list)print("Save the found ranking info to csv file, saving ...")df.to_csv('found.csv', encoding='utf_8_sig')return dfif __name__ == '__main__':found_all = get_fund_data()print(">>>>> The found all as:\n", found_all)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。