Py学习  »  Python

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

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

哈,今天生气之余,爬取了一下天天基金网前一阵子关注度最多的一支基金。最近一直在跌。因为工作的事生气了,但自己也冷静了。虽然生气,但学习不能忘。而且还成功地爬取到了。也算一点小收获吧。

import requests

import time

import execjs

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

print(netWorth)

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