婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

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

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

熱門標(biāo)簽:400電話 申請 條件 南京crm外呼系統(tǒng)排名 云南地圖標(biāo)注 鄭州智能外呼系統(tǒng)中心 汕頭電商外呼系統(tǒng)供應(yīng)商 crm電銷機器人 北京外呼電銷機器人招商 電銷機器人 金倫通信 賓館能在百度地圖標(biāo)注嗎

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

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

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

參考了網(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))

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

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

標(biāo)簽:石家莊 浙江 懷化 昆明 錫林郭勒盟 文山 西寧 梅州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python批量獲取基金數(shù)據(jù)的方法步驟》,本文關(guān)鍵詞  Python,批量,獲取,基金,數(shù)據(jù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Python批量獲取基金數(shù)據(jù)的方法步驟》相關(guān)的同類信息!
  • 本頁收集關(guān)于Python批量獲取基金數(shù)據(jù)的方法步驟的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 长武县| 漳州市| 阿瓦提县| 宣威市| 晋宁县| 斗六市| 铜梁县| 四会市| 会泽县| 兴义市| 永清县| 股票| 武宣县| 云林县| 新和县| 巴塘县| 开平市| 葫芦岛市| 罗田县| 嘉义县| 屏南县| 梨树县| 聂荣县| 北安市| 绍兴县| 温宿县| 崇礼县| 丰县| 云霄县| 财经| 乐山市| 老河口市| 分宜县| 贵州省| 遂平县| 喀喇沁旗| 泸定县| 陇南市| 铜川市| 即墨市| 德格县|