果然是中文编码的问题。搞定了,新鲜出炉一个小脚本。谢谢各位大神的解答。"""@Author:wenrongli@Date:2014-11-18@Version:V1.0"""#!/user/python#-*-coding:gb2312-*-importosimportsysimportgetoptfromWindPyimport*fromdatetimeimport*classLoadHisInfo:def__init__(self):self.OutputDir=r'E:'self.StockCodeList=[]defStartWind(self):w.start()defLoadStockList(self):res=w.wset("SectorConstituent","date=;sector=全部A股")ifres.ErrorCode!=0:print('Error['str(res.ErrorCode)'][loadstockcodelistfail]\n')sys.exit()foriinrange(0,len(res.Data[0])):forkinrange(0,len(res.Fields)):if(res.Fields[k]=='date'):date=res.Data[k][i]if(res.Fields[k]=="wind_code"):code=res.Data[k][i]if(res.Fields[k]=="sec_name"):name=res.Data[k][i]self.StockCodeList.append(code)defLoadHisInfo(self):forcodeinself.StockCodeList:outputPath=self.OutputDircoder'.txt'data=w.wsd(code,"open,high,low,close","19900101","",showblank=0)ifdata.ErrorCode!=0:print('Error['str(data.ErrorCode)'][loadhistoryinfofail]\n')sys.exit()fOutputObj=open(outputPath.encode('gbk'),'a')foriinrange(0,len(data.Data[0])):date=str(data.Times[i])forkinrange(0,len(data.Fields)):if(data.Fields[k]=="OPEN"):openPrice=data.Data[k][i]if(data.Fields[k]=="LOW"):lowPrice=data.Data[k][i]if(data.Fields[k]=="HIGH"):highPrice=data.Data[k][i]if(data.Fields[k]=="CLOSE"):closePrice=data.Data[k][i]if(openPrice==0)or(lowPrice==0)or(highPrice==0)or(closePrice==0):continueresult=date[0:10]","str(openPrice)","str(highPrice)","str(lowPrice)","str(closePrice)"\n"fOutputObj.write(result)fOutputObj.close()defRun(self):self.StartWind()self.LoadStockList()self.LoadHisInfo()if__name__=='__main__':loadInfoObj=LoadHisInfo()iflen(sys.argv)<3:print("pythonLoadWindInfo.py-ooutPutDir")sys.exit()opts,args=getopt.getopt(sys.argv[1:],"o:")forop,valueinopts:ifop=="-o":loadInfoObj.OutputDir=valueelse:print("pythonLoadWindInfo.py-ooutPutDir")sys.exit()loadInfoObj.Run()---------------------------------------------------------------------------------------------------------------------本来想获取A股股票代码列
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
,通过文档例子,返回了错误码-103,没找到这个错误码的说明,w.wset("SectorConstituent",u"date=20130608;sector=全部A股"),现在只能通过同花顺导出股票代码列表,然后通过配置文件的形式来拉数据,哪位大神知道怎么使用这个接口的还请赐教,不胜感激~~这里分享一个python获取A股历史交易数据的例子。#!/user/python#-*-coding:utf-8-*-importmathimportosimportsysimportgetoptfromWindPyimport*fromdecimalimport*fromdatetimeimport*WorkSpace='E:\\WorkSpace'data'\\data'config'\\config\\StockConfig.txt'url=''fConfigObj=open(config,"r")count=0forlineinfConfigObj.readlines():iflen(line)<8:continuecode=line[2:8]codeName=line[2:8]"."line[0:2]outputPath=r'E:/WorkSpace/data/'coder'.txt'w.start()data=w.wsd(codeName,"open,high,low,close","19900101","",showblank=0)ifdata.ErrorCode!=0:print('errorcode:'str(data.ErrorCode)'\n')sys.exit()fOutputObj=open(outputPath.encode('gbk'),'a')foriinrange(0,len(data.Data[0])):date=str(data.Times[i])forkinrange(0,len(data.Fields)):if(data.Fields[k]=="OPEN"):openPrice=data.Data[k][i]if(data.Fields[k]=="LOW"):lowPrice=data.Data[k][i]if(data.Fields[k]=="HIGH"):highPrice=data.Data[k][i]if(data.Fields[k]=="CLOSE"):closePrice=data.Data[k][i]if(openPrice==0)or(lowPrice==0)or(highPrice==0)or(closePrice==0):continueresult=date[0:10]","str(openPrice)","str(highPrice)","str(lowPrice)","str(closePrice)"\n"fOutputObj.write(result)fOutputObj.close()fConfigObj.close()