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

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

Python批量獲取基金數據的方法步驟

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

20年初準備投資基金,想爬取基金的業績數據。

20年基金迎來了爆發式增長,現把代碼開源以供參考。

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

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

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批量獲取基金數據內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家! 

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

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

巨人網絡通訊聲明:本文標題《Python批量獲取基金數據的方法步驟》,本文關鍵詞  Python,批量,獲取,基金,數據,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Python批量獲取基金數據的方法步驟》相關的同類信息!
  • 本頁收集關于Python批量獲取基金數據的方法步驟的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 吉首市| 扎赉特旗| 麻城市| 彝良县| 南木林县| 益阳市| 无为县| 正蓝旗| 河池市| 伽师县| 治多县| 彰化市| 沂南县| 福州市| 福贡县| 伊吾县| 资中县| 长宁县| 丁青县| 长武县| 登封市| 美姑县| 丹凤县| 温宿县| 奎屯市| 宜兰市| 静宁县| 金昌市| 庆城县| 林芝县| 洛南县| 泸溪县| 凌云县| 鸡西市| 邵东县| 建德市| 新竹县| 兴义市| 金湖县| 凤冈县| 宝鸡市|