介绍
本篇文章给大家分享的是有关使用Python怎么批量获取基金数据,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
Python可以做什么
Python是一种编程语言,内置了许多有效的工具,Python几乎无所不能,该语言通俗易懂,容易入门,功能强大,在许多领域中都有广泛的应用,例如最热门的大数据分析,人工智能,网页开发等。
import 请求 import 时间 import execjs 时间=start time.perf_counter () #,获取所有基金编的号 def getAllCode (): 时间=url 才能;& # 39;http://fund.eastmoney.com/js/fundcode_search.js& # 39; 时间=content 才能;requests.get (url) 时间=jsContent 才能;execjs.compile (content.text) rawData 才能=,jsContent.eval (& # 39; " # 39;) 时间=allCode 才能;[] for 才能;code  rawData:拷贝 ,,,allCode.append(代码[0]) return allCode才能 时间=allCode getAllCode () del allCode [100: len (allCode)] #,print (len (allCode)) #,获取基金编号为fscode的所有信息 def getUrl (fscode): 时间=head 才能;& # 39;http://fund.eastmoney.com/pingzhongdata/& # 39; 时间=tail 才能;& # 39;. js ? v=& # 39;, +, time.strftime (“% Y % m % d % H % m % S",, time.localtime ()) return 才能;head  +, fscode +尾巴 #,获取净值 def getWorth (fscode): 时间=content 才能;requests.get (getUrl (fscode)) 时间=jsContent 才能;execjs.compile (content.text) name 才能=,jsContent.eval (& # 39; fS_name& # 39;) code 才能=,jsContent.eval (& # 39; fS_code& # 39;) #才能,单位净值走势 netWorthTrend 才能=,jsContent.eval (& # 39; Data_netWorthTrend& # 39;) #,才能累计净值走势 ACWorthTrend 才能=,jsContent.eval (& # 39; Data_ACWorthTrend& # 39;) #才能,近一年收益率 Profit_12month 才能=,jsContent.eval (& # 39; syl_1n& # 39;) 时间=netWorth 才能;[] 时间=ACWorth 才能;[] for 才能;dayWorth 拷贝netWorthTrend [:: 1): ,,,netWorth.append (dayWorth [& # 39; y # 39;]) for 才能;dayACWorth 拷贝ACWorthTrend [:: 1): ,,,ACWorth.append (dayACWorth [1]) 打印才能(名称,代码) return 才能;榜,ACWorth 时间=netWorthFile 开放(& # 39;。/netWorth.csv& # 39;,, & # 39; w # 39;) 时间=ACWorthFile 开放(& # 39;。/ACWorth.csv& # 39;,, & # 39; w # 39;) for code  allCode拷贝: 尝试才能: 榜,,,,ACWorth =, getWorth(代码) 除了才能: ,才能继续 if 才能len(榜),& lt;=, 0,趁机len (ACWorth), & lt;, 0: ,,,#,打印(时间+ code “, empty data") ,才能继续 netWorthFile.write才能(“\ & # 39;“,+,code +,“\ & # 39;,“) netWorthFile.write才能(“、“. join(列表(map (str,榜)))) netWorthFile.write才能(“\ n") ACWorthFile.write才能(“\ & # 39;“,+,code +,“\ & # 39;,“) ACWorthFile.write才能(“、“. join(列表(map (str, ACWorth)))) ACWorthFile.write才能(“\ n") #,才能打印(“write “, +, code +,“,成功!”) netWorthFile.close () ACWorthFile.close () 最终获得=,time.perf_counter () 印刷(& # 39;Running 时间:,% s 秒# 39;,% (end-start))
以上就是使用Python怎么批量获取基金数据,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。