获取某网页基金净值

叫我瞄大人
import requests
import time
import execjs
import matplotlib.pyplot as plt
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):
    #用requests获取到对应的文件
 content = requests.get(getUrl(fscode))
   #使用execjs获取到相应的数据
 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')
    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
netWorth, ACWorth = getWorth('003511')
print(netWorth)
plt.figure(figsize=(10,5))
plt.plot(netWorth[:60][::-1])
plt.show()

image.png

阅读 931

个人编程学习
python,matlab,VB

喜欢追星的非科班的编程爱好者

461 声望
76 粉丝
0 条评论

喜欢追星的非科班的编程爱好者

461 声望
76 粉丝
文章目录
宣传栏