用python读取股票价格_python实时读取股票大单交易数据

代码如下,有时可以读取成功,有时显示错误Exception:'gb2312' codec can't decode bytes in position 1-2, 不晓得原因是什么,跪求大神指点~

# -*- coding: utf-8 -*-

import urllib

import time

def getStockDealData(stockCode):

try:

dataUrl = "http://stockpage.10jqka.com.cn/spService/"+stockCode+"/Funds/realFunds"

stdout = urllib.urlopen(dataUrl)

print stdout

stdoutInfo = stdout.read().decode('gb2312')

stdoutInfo=eval(stdoutInfo)

realDeal=[]

for i in stdoutInfo['flash']:

realDeal.append(i["sr"])

except Exception as e:

print(">>>>>> Exception: " + str(e))

finally:

None

if __name__ == '__main__':

start=time.clock()

getStockDealData("600000")

end=time.clock()

print end-start

你可能感兴趣的:(用python读取股票价格)