Write a python version of the gadget that can be used at work to brush your attention to the stock information. The Python version is 3.4.1, with the following code:
#!/usr/bin/env python#-*-coding:utf-8-*-import urllib.request#debug=truedebug=falseclass utility:def ToGB (str): if (Debug): Print (str) return Str.decode (' gb2312 ') class Stockinfo: "" "0: Unknown 1: Name 2: Code 3: When Previous price 4: Ups and downs 5:6%: Volume (Lot) 7: Turnover (million) 8:9: Total Market Value "" "Def Getstockstrbynum (num): f= URLLIB.R Equest.urlopen (' Http://qt.gtimg.cn/q=s_ ' + str (num)) if (Debug): Print (F.geturl ()) if (Debug): Print (F.info ()) #return like:v_s_sz000858= "51~ wuliangye ~000858~18.10~0.01~0.06~94583~17065~~687.07"; Return F.readline () f.close () def parseresultstr (RESULTSTR): if (Debug): Print (RESULTSTR) slist=res ULTSTR[14:-3] if (Debug): Print (slist) slist=slist.split (' ~ ') if (Debug): Print (slist) #print (' Print (' Stock name: ', slist[1]) print (' Stock code: ', Slist[2]) print (' Current price : ', slist[3]) print (' Ups and downs: ', slist[4]) Print (' Up%: ' slist[5], '% ') print (' Volume (Lot): ', slist[6]) print (' Turnover (million): ', slist[7]) #print ( ' Date and time is: ', dateandtime) print (' ******************************* ') def getstockinfo (num): str=st Ockinfo.getstockstrbynum (num) strgb=utility.togb (str) STOCKINFO.PARSERESULTSTR (STRGB) if __name__ = = ' __main_ _ ': Stocks = [' sh600888 ', ' sz300104 ', ' sz300027 ', ' sz000919 '] for the stock in Stocks:StockInfo.GetStockInfo (stock)
Python command line view stock Basic market data