def choose_period(self, period): ''' 时间选择 ''' if period == '1st quarter': period = '1 Half' elif period == '2nd quarter': period = '2 Half' else: return False period_xpath = '//a[@class="chosen-single"]' period_ele = ele_utils.get_include_hide_element_for_wait(self._driver, By.XPATH,\ period_xpath) if not period_ele: return False if not ele_utils.request_num(period_ele, self._driver): return False all_period_list_xpath = '//li[@class="active-result dopEvsWrap-select__item"]' all_period_list = ele_utils.get_elements_for_wait(self._driver, By.XPATH,\ all_period_list_xpath) if not all_period_list: return False period_ele = '' for one_period in all_period_list: if period in one_period.text: period_ele = one_period break if not period_ele: return False if not ele_utils.request_num(period_ele, self._driver): return False return True
def click_ok(self): ''' 点击确定按钮 ''' time.sleep(1) click_ok_xpath1 = '//button[@class=\ "c-btn c-btn--size-m c-btn--block c-btn--gradient c-btn--gradient-accent u-upcase"]' click_ok_xpath2 = '//span[@class="ui-button-text" and text()="OK"]' is_change = True num = 1 while True: print 'click-num:', num if num > 2: return False if is_change: click_ok_xpath = click_ok_xpath1 is_change = False else: click_ok_xpath = click_ok_xpath2 click_ok_ele = ele_utils.get_include_hide_element_for_wait( self._driver, By.XPATH, click_ok_xpath) if not click_ok_ele: num += 1 continue break if not ele_utils.request_num(click_ok_ele, self._driver): return False return True
def clear_bet(self): ''' 关闭投注窗口 ''' time.sleep(1) clear_bet_xpath1 = '//button[@class=\ "c-bet-box__del c-btn--close c-btn--flat c-btn--size-s c-btn c-btn--icon-only"]' clear_bet_xpath2 = '//div[@id="clearAllBetsBlock"]' is_change = True num = 1 while True: if num > 2: return False if is_change: clear_bet_xpath = clear_bet_xpath1 is_change = False else: clear_bet_xpath = clear_bet_xpath2 clear_bet_ele = ele_utils.get_include_hide_element_for_wait(self._driver, By.XPATH,\ clear_bet_xpath) if not clear_bet_ele: num += 1 continue break if not ele_utils.request_num(clear_bet_ele, self._driver): return False return True
def click_place_bet(self): ''' 输入金额后点击确定按钮 ''' click_place_bet_xpath1 = '//button[@class=\ "c-btn c-btn--size-l c-btn--block c-btn--gradient c-btn--gradient-accent u-upcase"]' click_place_bet_xpath2 = '//input[@id="goPutBetButton"]' is_change = True num = 1 while True: if num > 2: return False if is_change: click_place_bet_xpath = click_place_bet_xpath1 is_change = False else: click_place_bet_xpath = click_place_bet_xpath2 click_place_bet_ele = ele_utils.get_element_for_wait( self._driver, By.XPATH, click_place_bet_xpath, timeout=5) if not click_place_bet_ele: num += 1 continue break if not ele_utils.request_num(click_place_bet_ele, self._driver): return False return True
def operate_1x2(self, bet_name, home, away, period_kw=''): ''' 1x2操作 ''' if bet_name in mybooks.bet_1x2_list: hdp_1x2_init_xpath = '//div[@class="bet-title bet-title_justify" and contains(text(),\ "1x2%s")]/following-sibling::div' % (period_kw) else: hdp_1x2_init_xpath = '//div[@class="bet-title bet-title_justify" and (text()=\ " Double Chance%s ")]/following-sibling::div' % (period_kw) if bet_name == '1': remain_xpath = '/div/span[contains(text(), "%s")]' % home elif bet_name == 'X': remain_xpath = '/div/span[contains(text(), "%s")]' % ('Draw') elif bet_name == '2': remain_xpath = '/div/span[contains(text(), "%s")]' % away elif (bet_name == '1X') or (bet_name == 'X1'): remain_xpath = '/div/span[contains(text(), "%s")]' % (home + ' Or X') elif (bet_name == '2X') or (bet_name == 'X2'): remain_xpath = '/div/span[contains(text(), "%s")]' % (away + ' Or X') elif (bet_name == '12') or (bet_name == '21'): remain_xpath = '/div/span[contains(text(), "%s")]' % ( ('%s Or %s') % (home, away)) else: return False hdp_1x2_xpath = hdp_1x2_init_xpath + remain_xpath print hdp_1x2_xpath hdp_1x2_ele = ele_utils.get_include_hide_element_for_wait(self._driver, By.XPATH,\ hdp_1x2_xpath) if not hdp_1x2_ele: return False if not ele_utils.request_num(hdp_1x2_ele, self._driver): return False return True
def change_click_ok(self): ''' 赔率改变点击ok ''' change_click_ok_xpath = '//button[@class="ui-button ui-corner-all ui-widget"]' change_click_ok_ele = ele_utils.get_include_hide_element_for_wait(self._driver,\ By.XPATH, change_click_ok_xpath) if not change_click_ok_ele: return False if not ele_utils.request_num(change_click_ok_ele, self._driver): return False return True
def close_window_play_png(self): ''' 关闭比赛窗口 ''' close_xpath = '//span[@class="iconsBlock"]/a[@title="Close"]' close_ele = ele_utils.get_element_for_wait(self._driver, By.XPATH, close_xpath, timeout=2) if not close_ele: return False if not ele_utils.request_num(close_ele, self._driver): return False return True
def click_city_frame_close_btn(self): """关闭热门城市选择按钮""" close_btn_xpath = '//i[@id="closeXI20"]' close_btn_ele = ele_utils.get_include_hide_element_for_wait( self.driver, By.XPATH, close_btn_xpath, timeout=2) if not close_btn_ele: return False if not ele_utils.request_num(close_btn_ele): return False return True
def click_direct_flight_checkbox(self): """ 勾选直飞框 """ checkbox_xpath = '//label[@class="lab"]/input' checkbox_ele = ele_utils.get_include_hide_element_for_wait( self.driver, By.XPATH, checkbox_xpath, ) if not checkbox_ele: return False if not ele_utils.request_num(checkbox_ele): return False return True
def click_flight_search_btn(self): """点击机票搜索按钮""" if self.is_date_frame(): if not self.click_date_btn(): return False btn_xpath = '//div[@id="js_flighttype_tab_domestic"]/form/div[4]/\ button' btn_ele = ele_utils.get_include_hide_element_for_wait( self.driver, By.XPATH, btn_xpath) if not btn_ele: return False if not ele_utils.request_num(btn_ele): return False return True
def operate_ah(self, bet_name, bet_value, home, away, period_kw=''): ''' 让分盘操作 ''' # 判断是否亚洲让分盘 bet_value_tmp = float(bet_value) bet_value_abs = abs(bet_value_tmp) bet_value_int = int(bet_value_abs) remainder_val = bet_value_abs - bet_value_int if (remainder_val == 0.5) or (remainder_val == 0): hdp_ah_init_xpath = '//div[@class="bet-title bet-title_justify" and\ (text()=" Handicap%s ")]/following-sibling::div' % period_kw else: asian_handicap_text = 'Asian Handicap' # 通过输入框找到找到盘口类 if not self.search_input(asian_handicap_text): return False hdp_ah_init_xpath = '//div[text()=" %s%s "]/following-sibling::div'\ %(asian_handicap_text, period_kw) if float(bet_value) > 0: bet_value = '+%s' % (self.format_val(bet_value)) else: bet_value = self.format_val(bet_value) if (bet_name == 'AH1') or (bet_name == 'AH 1'): remain_xpath = '/div/span[text()="Handiсap %s (%s)"]' % (home, bet_value) elif (bet_name == 'AH2') or (bet_name == 'AH 2'): remain_xpath = '/div/span[text()="Handiсap %s (%s)"]' % (away, bet_value) else: return False hdp_ah_xpath = hdp_ah_init_xpath + remain_xpath print hdp_ah_xpath hdp_ah_ele = ele_utils.get_include_hide_element_for_wait(self._driver, By.XPATH,\ hdp_ah_xpath) if not hdp_ah_ele: return False if not ele_utils.request_num(hdp_ah_ele, self._driver): return False return True
def operate_ou(self, bet_name, bet_value, period_kw=''): ''' 大小球操作 ''' # 判断是否亚洲大小球 bet_value_tmp = float(bet_value) bet_value_abs = abs(bet_value_tmp) bet_value_int = int(bet_value_abs) remainder_val = bet_value_abs - bet_value_int if (remainder_val == 0.5) or (remainder_val == 0): hdp_ou_init_xpath = '//div[@class="bet-title bet-title_justify" and\ (text()=" Total%s ")]/following-sibling::div' % period_kw else: asian_total_text = 'Asian Total' # 通过输入框找到找到盘口类 if not self.search_input(asian_total_text): return False hdp_ou_init_xpath = '//div[text()=" %s%s "]/following-sibling::div'\ %(asian_total_text, period_kw) bet_value_str = self.format_val(bet_value) if (bet_name == 'TO') or (bet_name == 'Over'): remain_xpath = '/div/span[text()="Total Over %s"]' % ( bet_value_str) elif (bet_name == 'TU') or (bet_name == 'Under'): remain_xpath = '/div/span[text()="Total Under %s"]' % ( bet_value_str) else: return False hdp_ou_xpath = hdp_ou_init_xpath + remain_xpath print hdp_ou_xpath hdp_ou_ele = ele_utils.get_include_hide_element_for_wait(self._driver,\ By.XPATH, hdp_ou_xpath, timeout=4) if not hdp_ou_ele: return False if not ele_utils.request_num(hdp_ou_ele, self._driver): return False return True