python实现股市信息下载的方法

本文实例讲述了python实现股市信息下载的方法。分享给大家供大家参考。具体如下:

该程序下载来自yahoo财经的股市信息。

import urllib
def geturl(url):
socket = urllib.urlopen(url)
readsocket = socket.read()
socket.close()
return readsocket
def printinfo(listinfo):
print “stock symbol: ” , listinfo[0]
print “last trade price: ” , listinfo[1]
print “last trade date: ” , listinfo[2]
print “last trade time: ” , listinfo[3]
print “change: ” , listinfo[4]
print “open: ” , listinfo[5]
print “day’s high: ” , listinfo[6]
print “day’s low: ” , listinfo[7]
print “volume: ” , listinfo[8]
stocksymbol = raw_input(“enter the stock symbol: “)
stockurl = “http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv&e=.csv” % stocksymbol
stockinfostr = geturl(stockurl)
stockinfostr = stockinfostr.rstrip()
stockinfostr = stockinfostr.split(“,”)
printinfo(stockinfostr)

希望本文所述对大家的python程序设计有所帮助。