Work time through the browser to open the stock website afraid to be seen by others, it doesn't matter, try to execute code under the command line to see the data on the line.
Input sh, you can view the Shanghai Composite
Enter SZ, you can view the Shenzhen index
Enter CYB to view Gem index
Other stock codes can be customized and added to the dictionary.
Python version 2.7.3
#!/usr/bin/env python#-*-coding:utf-8-*-import urllib2import reimport datetime def getstockinfo (URL): "" "Get information based on URL" "" stocklist = [] request = Urllib2. Request (URL) response = Urllib2.urlopen (request) Stockstr = Response.read () stocklist = Stockstr.split (', ') r Eturn stocklist def printstock (List): "" "Printing Information" "" Print ' ***********price***************** ' + list[1] print ' * * * float_price*********** ' + list[2] print ' ***********float_perct*********** ' + list[3] + '% ' print ' ********* **succ_unit************* ' + list[4]+ ' shou ' print ' ***********succ_price************ ' + list[5] def getUrlByCode (code): "" "Get detailed URL according to code" "" url = ' Stockcode = ' if code = = ' sh ': url = ' http://hq.sinajs.cn/list=s_sh000001 ' Elif code = = ' sz ': url = ' http://hq.sinajs.cn/list=s_sz399001 ' elif code = = ' cyb ': url = ' HTTP://HQ. sinajs.cn/list=s_sz399006 ' Else:pattern = Re.compile (R ' ^60* ') match = Pattern.match (coDE) if Match:stockcode = ' sh ' + code else:stockcode = ' sz ' + code URL = ' http: Hq.sinajs.cn/list=s_ ' +stockcode return url #输入stock代码输出对应的价格信息 #code = raw_input (' Code: ') codedict = {' sh ': ' Shang Hai zq ', ' sz ': ' Shen Zheng zq ', ' cyb ': ' Chang ye ban ', ' 601788 ': ' Guang da Zheng Quan ', ' 000 651 ': ' ge li Dian qi ',} #http://hq.sinajs.cn/list=s_sh000001 (Shanghai market Query) #http://hq.sinajs.cn/list=s_sz399001 (Shenzhen market query) Count = 0;while (count<=100): #循环100次后再退出 # Loop dictionary for key in Codedict:print key + '--' +codedict[key] Co de = raw_input (' Please select a code: ') Now_time = Datetime.datetime.now () #打印该code的信息 url = geturlbycode (code) Stockinfo = Getstockinfo (URL) #print stockinfo printstock (stockinfo) end_time = Datetime.datetime.now () c Osttime = (end_time-now_time). Seconds print ' total time spent ' +str (costtime) + ' s ' Count +=1