佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > Python批量獲取基金數(shù)據(jù)的方法步驟

Python批量獲取基金數(shù)據(jù)的方法步驟

熱門標簽:呼叫中心市場需求 電話運營中心 Win7旗艦版 企業(yè)做大做強 百度AI接口 語音系統(tǒng) 客戶服務 硅谷的囚徒呼叫中心

20年初準備投資基金,想爬取基金的業(yè)績數(shù)據(jù)。

20年基金迎來了爆發(fā)式增長,現(xiàn)把代碼開源以供參考。

本代碼只能實現(xiàn)初步匯總,輸出csv文件來保存基金的單位累計凈值,后期仍需要結合統(tǒng)計方法來篩選優(yōu)質基金。

參考了網(wǎng)上的部分代碼,實在不記得出處了,侵刪。

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批量獲取基金數(shù)據(jù)的方法步驟的文章就介紹到這了,更多相關Python批量獲取基金數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家! 

您可能感興趣的文章:
  • python 簡單的股票基金爬蟲
  • Python獲取基金網(wǎng)站網(wǎng)頁內(nèi)容、使用BeautifulSoup庫分析html操作示例
  • Python多進程方式抓取基金網(wǎng)站內(nèi)容的方法分析
  • Python學習筆記之抓取某只基金歷史凈值數(shù)據(jù)實戰(zhàn)案例
  • 利用python實時刷新基金估值(摸魚小工具)

標簽:長沙 濟南 山西 海南 喀什 崇左 安康 山西

巨人網(wǎng)絡通訊聲明:本文標題《Python批量獲取基金數(shù)據(jù)的方法步驟》,本文關鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    裕民县| 商河县| 呼伦贝尔市| 新闻| 江油市| 息烽县| 泰宁县| 石城县| 崇阳县| 龙陵县| 庆阳市| 襄樊市| 怀集县| 潜山县| 乌拉特后旗| 平乐县| 湘潭县| 湘潭市| 乌兰浩特市| 萝北县| 班戈县| 扎囊县| 龙口市| 景泰县| 湘阴县| 高要市| 万荣县| 康保县| 沈阳市| 安乡县| 子长县| 稷山县| 抚宁县| 冕宁县| 巩义市| 孝感市| 徐闻县| 宜州市| 称多县| 乌苏市| 遵义市|