打算用python做一些股票数据采集的工具,下面这个用来展示当前热门行业,python代码如下
- 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')
复制代码