栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

通过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': 'http://fund.eastmoney.com/data/fundranking.html',
        'cookie': 'st_si=51694067779834; st_asi=delete; ASP.NET_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=2021-09-23%2000%3A05%3A17; st_inirUrl=http%3A%2F%2Ffund.eastmoney.com%2Fdata%2Ffundranking.html; st_sn=15; st_psi=20210923011636912-0-9218336114'
    }

    url2 = 'http://fund.eastmoney.com/data/rankhandler.aspx?op=ph&dt=kf&ft=all&rs=&gs=0&sc=6yzf&st=desc&sd=2020-09-25&ed=2021-09-25&qdii=&tabSubtype=,,,,,&pi=1&pn=10000&dx=1&v=0.8910858366202241'
    response = requests.get(url2, headers=header)
    text = response.text
    compile_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 df

if __name__ == '__main__':
	found_all = get_fund_data()
    print(">>>>> The found all as:n", found_all)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/286397.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号