下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
上班时间通过浏览器打开股票网站怕会被别人看到,没关系,试试在命令行下执行代码看数据就行了。输入sh,就可以查看到上证指数
输入sz,就可以查看深圳指数
输入cyb,就可以查看创业板指数
其他的股票代码可以自己自定义,加入到字典中就行了
python版本2.7.3
#!/usr/bin/env python# -*- Coding: utf-8 -*-import urllib2import reimport datetimedef getStockInfo(url): """根据url获取信息""" stockList = [] request = urllib2.Request(url) response = urllib2.urlopen(request) stockStr = response.read() stockList = stockStr.split(',') return stockListdef printStock(List): """打印相关信息""" 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): """根据代码获取详细的url""" 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','000651' : 'ge li dian qi',}#http://hq.sinaJs.cn/List=s_sh000001 (上海大盘查询)#http://hq.sinaJs.cn/List=s_sz399001 (深圳大盘查询)count = 0;while (count<=100):#循环100次后再退出 # 循环字典 for key in codeDict: print key + '--'+codeDict[key] code = 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() costTime = (end_time - Now_time).seconds print '总共花费时间'+str(costTime)+'秒' count +=1
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的python根据股票代码获取当前数据全部内容,希望文章能够帮你解决python根据股票代码获取当前数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)