社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python网络爬虫10:爬取基金净值数据2

浮云的痛 • 3 年前 • 308 次点击  

结合上次的学习,这次加个折线图,不过还没研究出如何在图上加年份。

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()

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/106459
 
308 次点击