#coding=utf-8 from selenium import webdriver from time import sleep from selenium.webdriver.common.keys import Keys import os touzhu = {} strbz = 'd:/bzcs.txt' strsj = 'd:/sjcs.txt' def touNum(): for i in xrange(0, 28): touzhu[i] = 0 dr = webdriver.Firefox() dr.get('http://pceggs.com/play/PG28Trend.aspx') sleep(30) contents= dr.find_elements_by_class_name("sz_top") zh = dr.find_element_by_xpath("//img[contains(@src,'/img/xnbc')]") zhnum = zh.get_attribute('src') if(zhnum[35] == '.'): zhnum = zhnum[34:35] else: zhnum = zhnum[34:36] print(zhnum) inum = int(zhnum) touzhu[inum] = 1; icnt = 0; biaozhuncishu = []; shijicishu =[] for content in contents: if(icnt == 3 ): biaozhuncishu = content.text biaozhuncishu = biaozhuncishu.strip(' ') biaozhuncishu = biaozhuncishu.strip('标准次数'.decode('utf-8')) if os.path.exists(strbz): os.remove(strbz) fobj = open(strbz,'wb') biaozhuncishu = biaozhuncishu[1:] fobj.writelines(biaozhuncishu) fobj.close() elif(icnt == 4): shijicishu = content.text shijicishu = shijicishu.strip(' ') shijicishu = shijicishu.strip('实际次数'.decode('utf-8')) shijicishu = shijicishu.strip('尾数 余'.decode('utf-8')) if os.path.exists(strsj): os.remove(strsj) fobj = open(strsj,'wb') fobj.writelines(shijicishu) fobj.close() icnt +=1 #duqu foba = open(strbz,'rb') line=foba.readline() while line: arrbz=line.split(' ') line=foba.readline() foba.close() fobb = open(strsj,'rb') linesj=fobb.readline() while linesj: arrsj=linesj.split(' ') linesj=fobb.readline() fobb.close() isnum =0; for i in xrange(0,28): #print(i,arrsj[i] ,arrbz[i]) if(int(arrsj[i]) >= int(arrbz[i])): touzhu[i] =1 #print(isnum) #isnum += 1 sleep(5) #dr.get('http://pceggs.com/play/pc28.aspx') #sleep(10) #dr.refresh() print("投注数字:".decode('utf-8')) for i in xrange(0,28): if(touzhu[i] == 1): print(i) dr.quit() if __name__ == "__main__": touNum()