ITPub博客

首页 > > > Python爬取上交所一年大盘数据

Python爬取上交所一年大盘数据

作者:cjk 时间:2019-12-03 17:14:02 0 删除 编辑

前言

文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。


这次我们用requests、json来爬取上交所A股大盘的数据,并以收盘价为坐标画出2018-2019年的走势。 要爬取的界面如下:

具体爬虫代码如下:

import json
import requests
import matplotlib.pyplot as plt
#爬取程序
def load_sse(): 
 url='http://yunhq.sse.com.cn:32041/v1/sh1/dayk/000001?callback=jQuery111208282462776376776_1569062885488&select=date%2Copen%2Chigh%2Clow%2Cclose%2Cvolume&begin=-300&end=-1&_=1569062885522' 
 response=requests.get(url,headers={'Referer': 'http://www.sse.com.cn/market/price/trends/'})
 json_str=response.text[42:-1]
 data=json.loads(json_str)
 return data['kline'] 
#画图
def draw(data):
 date=[x[0] for x in data]
 close=[x[4] for x in data] 
 #对x轴进行处理
 index=range(len(date))
 limit=90
 plt.xticks(index[::limit],date[::limit])
 #画图
 plt.plot(index,close,'red')
if __name__=='__main__':
 kline=load_sse()
 draw(kline)


画图如下:

好了,See you!这只是用收盘价格画出来的折线,明天我们画出它的K线(蜡烛图)。



来源:嗨学python

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4715/viewspace-3137844/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 类A复制类B
请登录后发表评论 登录
全部评论

注册时间:2019-04-29

  • 博文量
    181
  • 访问量
    1134