python真的是越来越流行了,再不学感觉就会被淘汰的样子,另外一直想学习炒股,所以两个一结合就打算做一些python爬虫工具,可以将自己关注的股票信息汇总并分析出有用的信息,下面这个是爬取新浪财经行业信息并分析热门行业。
2018-05-08_091849.png
import requests
import json
import pygal
r = requests.get("http://money.finance.sina.com.cn/q/view/newFLJK.php?param=industry")
r.encoding='gbk'
print (r.encoding)
rText = r.text
rText = rText[rText.index('{'):]
data = json.loads(rText)
industryData = {'name':[],'totalContractValue':[]};
for (key,value) in data.items():
valueArray = value.split(',')
if float(valueArray[-4]) > 10:
industryData['name'].append(valueArray[1])
industryData['totalContractValue'].append(round(float(valueArray[7]) / 10000,2))
print (industryData)
hist = pygal.Bar()
hist.title = '热闹行业总成交额'
hist.x_labels = industryData['name']
hist.x_title = '行业名称'
hist.y_title = '总成交额(万)'
hist.add('总成交额', industryData['totalContractValue'])
hist.render_to_file('industry.svg')