-
大小: 3KB文件類型: .py金幣: 1下載: 0 次發(fā)布日期: 2021-06-01
- 語言: Python
- 標簽: A股數(shù)據(jù)??新浪財經(jīng)??python??
資源簡介
通過不斷調(diào)用新浪財經(jīng)的API獲取A股的實時數(shù)據(jù),包括實時數(shù)據(jù),最高最低價,昨日收盤價,買5,賣5的成交價,成交量等信息,并可以實時進行分時圖的繪畫。
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
#?author:llx??time:?2018/1/3
import?requests
import?time?as?time_sleep
import?pandas?as?pd
import?matplotlib.pyplot?as?plt
import?matplotlib.dates?as?mdates
from?datetime?import?datetime
def?getHTMLText(url):
????try:
????????r?=?requests.get(url?timeout=30)
????????r.raise_for_status()
????????r.encoding?=?r.apparent_encoding??#?‘utf-8‘?#
????????return?r.text
????except:
????????return?“?“
def?getData(data):
????data?=?data.split(‘‘)
????#?name?=?data[0]
????todayOpen?=?data[1]
????yesterdayClose?=?data[2]
????nowPrice?=?data[3]
????todayHigh?=?data[4]
????todayLow?=?data[5]
????bidPrice?=?data[6]
????askPrice?=?data[7]
????quantity?=?data[8]
????money?=?data[9]
????buy1Volume?=?data[10]
????buy1Price?=?data[11]
????buy2Volume?=?data[12]
????buy2Price?=?data[13]
????buy3Volume?=?data[14]
????buy3Price?=?data[15]
????buy4Volume?=?data[16]
????buy4Price?=?data[17]
????buy5Volume?=?data[18]
????buy5Price?=?data[19]
????sell1Volume?=?data[20]
????sell1Price?=?data[21]
????sell2Volume?=?data[22]
????sell2Price?=?data[23]
????sell3Volume?=?data[24]
????sell3Price?=?data[25]
????sell4Volume?=?data[26]
????sell4Price?=?data[27]
????sell5Volume?=?data[28]
????sell5Price?=?data[29]
????date?=?data[30]
????time?=?data[31]
????data?=?{‘todayOpen‘:?todayOpen?‘yesterdayClose‘:?yesterdayClose?‘nowPrice‘:?nowPrice?‘todayHigh‘:?todayHigh
????????????‘todayLow‘:?todayLow?‘bidPrice‘:?bidPrice?‘a(chǎn)skPrice‘:?askPrice?‘quantity‘:?quantity?‘money‘:?money
????????????‘buy1Volume‘:?buy1Volume?‘buy1Price‘:?buy1Price?‘buy2Volume‘:?buy2Volume?‘buy2Price‘:?buy2Price
???
- 上一篇:文本分類算法LDA
- 下一篇:python爬蟲抓取百度貼吧中郵箱地址
評論
共有 條評論