结合上次的学习,这次加个折线图,不过还没研究出如何在图上加年份。
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')
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') # 累计净值走势数据
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('007119')
print(netWorth)
plt.figure(figsize=(10,5))
plt.plot(netWorth[:60][::-1])
plt.show()
网友评论