使用Python怎么批量獲取基金數(shù)據(jù)-創(chuàng)新互聯(lián)

本篇文章給大家分享的是有關(guān)使用Python怎么批量獲取基金數(shù)據(jù),小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說(shuō),跟著小編一起來(lái)看看吧。

創(chuàng)新互聯(lián)建站:從2013年開始為各行業(yè)開拓出企業(yè)自己的“網(wǎng)站建設(shè)”服務(wù),為上千公司企業(yè)提供了專業(yè)的做網(wǎng)站、成都做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)和網(wǎng)站推廣服務(wù), 按需求定制網(wǎng)站由設(shè)計(jì)師親自精心設(shè)計(jì),設(shè)計(jì)的效果完全按照客戶的要求,并適當(dāng)?shù)奶岢龊侠淼慕ㄗh,擁有的視覺效果,策劃師分析客戶的同行競(jìng)爭(zhēng)對(duì)手,根據(jù)客戶的實(shí)際情況給出合理的網(wǎng)站構(gòu)架,制作客戶同行業(yè)具有領(lǐng)先地位的。

python可以做什么

Python是一種編程語(yǔ)言,內(nèi)置了許多有效的工具,Python幾乎無(wú)所不能,該語(yǔ)言通俗易懂、容易入門、功能強(qiáng)大,在許多領(lǐng)域中都有廣泛的應(yīng)用,例如最熱門的大數(shù)據(jù)分析,人工智能,Web開發(fā)等。

import requests
import time
import execjs
start = time.perf_counter()

# 獲取所有基金編號(hào)
def getAllCode():
  url = 'http://fund.eastmoney.com/js/fundcode_search.js'
  content = requests.get(url)
  jsContent = execjs.compile(content.text)
  rawData = jsContent.eval('r')
  allCode = []
  for code in rawData:
    allCode.append(code[0])
  return allCode

allCode = getAllCode()
del allCode[100:len(allCode)]
# print(len(allCode))

# 獲取基金編號(hào)為fscode的所有信息
def getUrl(fscode):
  head = 'http://fund.eastmoney.com/pingzhongdata/'
  tail = '.js?v=' + time.strftime("%Y%m%d%H%M%S", time.localtime())
  return head + fscode + tail

# 獲取凈值
def getWorth(fscode):
  content = requests.get(getUrl(fscode))
  jsContent = execjs.compile(content.text)

  name = jsContent.eval('fS_name')
  code = jsContent.eval('fS_code')
  # 單位凈值走勢(shì)
  netWorthTrend = jsContent.eval('Data_netWorthTrend')
  # 累計(jì)凈值走勢(shì)
  ACWorthTrend = jsContent.eval('Data_ACWorthTrend')
  # 近一年收益率
  Profit_12month = jsContent.eval('syl_1n')

  netWorth = []
  ACWorth = []

  for dayWorth in netWorthTrend[::-1]:
    netWorth.append(dayWorth['y'])

  for dayACWorth in ACWorthTrend[::-1]:
    ACWorth.append(dayACWorth[1])
  print(name, code)
  return netWorth, ACWorth

netWorthFile = open('./netWorth.csv', 'w')
ACWorthFile = open('./ACWorth.csv', 'w')

for code in allCode:
  try:
    netWorth, ACWorth = getWorth(code)
  except:
    continue
  if len(netWorth) <= 0 or len(ACWorth) < 0:
    # print(code + " empty data")
    continue
  netWorthFile.write("\'" + code + "\',")
  netWorthFile.write(",".join(list(map(str, netWorth))))
  netWorthFile.write("\n")

  ACWorthFile.write("\'" + code + "\',")
  ACWorthFile.write(",".join(list(map(str, ACWorth))))
  ACWorthFile.write("\n")
  # print("write " + code + " success.")

netWorthFile.close()
ACWorthFile.close()
end = time.perf_counter()
print('Running time: %s seconds' %(end-start))

以上就是使用Python怎么批量獲取基金數(shù)據(jù),小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

標(biāo)題名稱:使用Python怎么批量獲取基金數(shù)據(jù)-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)鏈接:http://muchs.cn/article32/djjspc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站改版、外貿(mào)建站、面包屑導(dǎo)航、關(guān)鍵詞優(yōu)化、軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)