网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

使用Python怎么批量获取基金数据-创新互联

本篇文章给大家分享的是有关使用Python怎么批量获取基金数据,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

创新互联建站:从2013年开始为各行业开拓出企业自己的“网站建设”服务,为上千公司企业提供了专业的做网站、成都做网站、网页设计和网站推广服务, 按需求定制网站由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。

python可以做什么

Python是一种编程语言,内置了许多有效的工具,Python几乎无所不能,该语言通俗易懂、容易入门、功能强大,在许多领域中都有广泛的应用,例如最热门的大数据分析,人工智能,Web开发等。

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

# 获取所有基金编号
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))

# 获取基金编号为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')
  # 单位净值走势
  netWorthTrend = jsContent.eval('Data_netWorthTrend')
  # 累计净值走势
  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怎么批量获取基金数据,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。


分享标题:使用Python怎么批量获取基金数据-创新互联
分享URL:http://bjjierui.cn/article/djjspc.html

其他资讯