2022-10-19, fix kktix captcha text guess.
parent
43d0d73cd5
commit
3e520fa4bf
|
@ -66,7 +66,7 @@ ssl._create_default_https_context = ssl._create_unverified_context
|
|||
#附註1:沒有寫的很好,很多地方應該可以模組化。
|
||||
#附註2:
|
||||
|
||||
CONST_APP_VERSION = u"MaxBot (2022.09.19)"
|
||||
CONST_APP_VERSION = u"MaxBot (2022.10.19)"
|
||||
|
||||
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
|
||||
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
|
||||
|
@ -373,7 +373,7 @@ def load_config_from_local(driver):
|
|||
#import seleniumwire.undetected_chromedriver as uc
|
||||
|
||||
# method 6: Selenium Stealth
|
||||
if driver_type=="stealth":
|
||||
if driver_type != "undetected_chromedriver":
|
||||
from selenium_stealth import stealth
|
||||
|
||||
chrome_options = webdriver.ChromeOptions()
|
||||
|
@ -403,6 +403,9 @@ def load_config_from_local(driver):
|
|||
# method 6: Selenium Stealth
|
||||
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
|
||||
|
||||
if driver_type=="stealth":
|
||||
from selenium_stealth import stealth
|
||||
|
||||
# Selenium Stealth settings
|
||||
stealth(driver,
|
||||
languages=["zh-TW", "zh"],
|
||||
|
@ -488,6 +491,9 @@ def load_config_from_local(driver):
|
|||
except Exception as excSwithFail:
|
||||
pass
|
||||
|
||||
if driver is None:
|
||||
print("create web driver object fail @_@;")
|
||||
else:
|
||||
try:
|
||||
print("goto url:", homepage)
|
||||
driver.get(homepage)
|
||||
|
@ -1524,7 +1530,6 @@ def kktix_events_press_next_button(driver):
|
|||
if next_step_button.is_enabled():
|
||||
next_step_button.click()
|
||||
ret = True
|
||||
|
||||
except Exception as exc:
|
||||
print("wait form-actions div wait to be clickable Exception:")
|
||||
#print(exc)
|
||||
|
@ -1599,15 +1604,20 @@ def kktix_captcha_text_value(captcha_inner_div):
|
|||
return ret
|
||||
|
||||
def kktix_input_captcha_text(captcha_inner_div, captcha_password_string, force_overwrite = False):
|
||||
show_debug_message = True # debug.
|
||||
#show_debug_message = False # online
|
||||
|
||||
ret = False
|
||||
|
||||
if captcha_inner_div is not None and captcha_password_string is not None:
|
||||
try:
|
||||
if captcha_inner_div is not None:
|
||||
#print("found captcha div")
|
||||
if captcha_password_string is not None:
|
||||
if show_debug_message:
|
||||
print("found captcha div")
|
||||
captcha_password_text = captcha_inner_div.find_element(By.TAG_NAME, "input")
|
||||
if not captcha_password_text is None:
|
||||
#print("found input field")
|
||||
if show_debug_message:
|
||||
print("found input field")
|
||||
|
||||
inputed_captcha_text = captcha_password_text.get_attribute('value')
|
||||
if force_overwrite:
|
||||
captcha_password_text.send_keys(captcha_password_string)
|
||||
|
@ -1619,12 +1629,11 @@ def kktix_input_captcha_text(captcha_inner_div, captcha_password_string, force_o
|
|||
captcha_password_text.send_keys(captcha_password_string)
|
||||
print("send captcha keys:" + captcha_password_string)
|
||||
ret = True
|
||||
|
||||
else:
|
||||
print("find captcha input field fail")
|
||||
except Exception as exc:
|
||||
if show_debug_message:
|
||||
print("find kktix_input_captcha_text Exception:")
|
||||
#print(exc)
|
||||
print(exc)
|
||||
pass
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -1763,20 +1772,33 @@ def kktix_assign_ticket_number(driver, ticket_number, kktix_area_keyword):
|
|||
return ret
|
||||
|
||||
def kktix_get_web_datetime(url, registrationsNewApp_div):
|
||||
show_debug_message = True # debug.
|
||||
#show_debug_message = False # online
|
||||
|
||||
web_datetime = None
|
||||
|
||||
el_web_datetime = None
|
||||
is_found_web_datetime = False
|
||||
try:
|
||||
|
||||
el_web_datetime_list = None
|
||||
if not registrationsNewApp_div is None:
|
||||
try:
|
||||
el_web_datetime_list = registrationsNewApp_div.find_elements(By.TAG_NAME, 'td')
|
||||
except Exception as exc:
|
||||
if show_debug_message:
|
||||
print("find td.ng-binding Exception")
|
||||
print(exc)
|
||||
pass
|
||||
#print("is_found_web_datetime", is_found_web_datetime)
|
||||
|
||||
if el_web_datetime_list is not None:
|
||||
el_web_datetime_list_count = len(el_web_datetime_list)
|
||||
if el_web_datetime_list_count > 0:
|
||||
el_web_datetime = None
|
||||
for el_web_datetime in el_web_datetime_list:
|
||||
try:
|
||||
el_web_datetime_text = el_web_datetime.text
|
||||
#print("el_web_datetime_text:", el_web_datetime_text)
|
||||
if show_debug_message:
|
||||
print("el_web_datetime_text:", el_web_datetime_text)
|
||||
|
||||
now = datetime.now()
|
||||
#print("now:", now)
|
||||
|
@ -1791,14 +1813,12 @@ def kktix_get_web_datetime(url, registrationsNewApp_div):
|
|||
if is_found_web_datetime:
|
||||
break
|
||||
except Exception as exc:
|
||||
#print(exc)
|
||||
if show_debug_message:
|
||||
print('parse web datetime fail:')
|
||||
print(exc)
|
||||
pass
|
||||
else:
|
||||
print("find td.ng-binding fail")
|
||||
except Exception as exc:
|
||||
#print("find td.ng-binding Exception")
|
||||
pass
|
||||
#print("is_found_web_datetime", is_found_web_datetime)
|
||||
|
||||
return web_datetime
|
||||
|
||||
|
@ -1884,6 +1904,9 @@ def kktix_check_register_status(url):
|
|||
return registerStatus
|
||||
|
||||
def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_checkbox_click, auto_fill_ticket_number, ticket_number, kktix_area_keyword):
|
||||
show_debug_message = True # debug.
|
||||
#show_debug_message = False # online
|
||||
|
||||
#---------------------------
|
||||
# part 2: ticket number
|
||||
#---------------------------
|
||||
|
@ -1916,6 +1939,9 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
pass
|
||||
|
||||
if captcha_inner_div is not None:
|
||||
if show_debug_message:
|
||||
print("found captcha_inner_div layor.")
|
||||
|
||||
captcha_text_div = None
|
||||
try:
|
||||
captcha_text_div = captcha_inner_div.find_element(By.TAG_NAME, "p")
|
||||
|
@ -1934,6 +1960,9 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
except Exception as exc:
|
||||
pass
|
||||
|
||||
if show_debug_message:
|
||||
print("captcha_text_div_text:", captcha_text_div_text)
|
||||
|
||||
#captcha_text_div_text = u"請回答下列問題,請在下方空格輸入DELIGHT(請以半形輸入法作答,大小寫需要一模一樣)"
|
||||
#captcha_text_div_text = u"請在下方空白處輸入引號內文字:「abc」"
|
||||
#captcha_text_div_text = u"請在下方空白處輸入引號內文字:「0118eveconcert」(請以半形小寫作答。)"
|
||||
|
@ -2019,7 +2048,8 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
|
||||
# parse '演出日期'
|
||||
is_need_parse_web_datetime = False
|
||||
if u'半形數字' in captcha_text_div_text:
|
||||
# '半形阿拉伯數字' & '半形數字'
|
||||
if u'半形' in captcha_text_div_text and u'字' in captcha_text_div_text:
|
||||
if u'演出日期' in captcha_text_div_text:
|
||||
is_need_parse_web_datetime = True
|
||||
if u'活動日期' in captcha_text_div_text:
|
||||
|
@ -2037,38 +2067,45 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
if u'the date of the show you purchased' in captcha_text_div_text:
|
||||
is_need_parse_web_datetime = True
|
||||
|
||||
#print("is_need_parse_web_datetime:", is_need_parse_web_datetime)
|
||||
if show_debug_message:
|
||||
print("is_need_parse_web_datetime:", is_need_parse_web_datetime)
|
||||
|
||||
if is_need_parse_web_datetime:
|
||||
captcha_password_string = None
|
||||
web_datetime = kktix_get_web_datetime(url, registrationsNewApp_div)
|
||||
if not web_datetime is None:
|
||||
tmp_text = captcha_text_div_text
|
||||
# replace ex.
|
||||
tmp_text = tmp_text.replace(u'例如',u'範例')
|
||||
tmp_text = tmp_text.replace(u'如:',u'範例:')
|
||||
tmp_text = tmp_text.replace(u'舉例',u'範例')
|
||||
if not u'範例' in tmp_text:
|
||||
tmp_text = tmp_text.replace(u'例',u'範例')
|
||||
# important, maybe 例 & ex occurs at same time.
|
||||
tmp_text = tmp_text.replace(u'ex:',u'範例:')
|
||||
if show_debug_message:
|
||||
print("web_datetime:", web_datetime)
|
||||
|
||||
tmp_text = tmp_text.replace(u'輸入:',u'範例')
|
||||
tmp_text = tmp_text.replace(u'輸入',u'範例')
|
||||
#print("tmp_text", tmp_text)
|
||||
captcha_text_formatted = captcha_text_div_text
|
||||
# replace ex.
|
||||
captcha_text_formatted = captcha_text_formatted.replace(u'例如',u'範例')
|
||||
captcha_text_formatted = captcha_text_formatted.replace(u'如:',u'範例:')
|
||||
captcha_text_formatted = captcha_text_formatted.replace(u'舉例',u'範例')
|
||||
if not u'範例' in captcha_text_formatted:
|
||||
captcha_text_formatted = captcha_text_formatted.replace(u'例',u'範例')
|
||||
# important, maybe 例 & ex occurs at same time.
|
||||
captcha_text_formatted = captcha_text_formatted.replace(u'ex:',u'範例:')
|
||||
|
||||
captcha_text_formatted = captcha_text_formatted.replace(u'輸入:',u'範例')
|
||||
captcha_text_formatted = captcha_text_formatted.replace(u'輸入',u'範例')
|
||||
|
||||
if show_debug_message:
|
||||
print("captcha_text_formatted", captcha_text_formatted)
|
||||
|
||||
my_datetime_foramted = None
|
||||
|
||||
if my_datetime_foramted is None:
|
||||
if u'4位半形數字' in tmp_text:
|
||||
if u'4位半形' in captcha_text_formatted:
|
||||
my_datetime_foramted = "%m%d"
|
||||
|
||||
if my_datetime_foramted is None:
|
||||
now = datetime.now()
|
||||
for guess_year in range(now.year-1,now.year+3):
|
||||
for guess_year in range(now.year-4,now.year+2):
|
||||
current_year = str(guess_year)
|
||||
if current_year in tmp_text:
|
||||
my_hint_index = tmp_text.find(current_year)
|
||||
my_hint_anwser = tmp_text[my_hint_index:]
|
||||
if current_year in captcha_text_formatted:
|
||||
my_hint_index = captcha_text_formatted.find(current_year)
|
||||
my_hint_anwser = captcha_text_formatted[my_hint_index:]
|
||||
#print("my_hint_anwser:", my_hint_anwser)
|
||||
# get after.
|
||||
my_delimitor_symbol = u'範例'
|
||||
|
@ -2090,13 +2127,22 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
if my_delimitor_symbol in my_hint_anwser:
|
||||
my_delimitor_index = my_hint_anwser.find(my_delimitor_symbol)
|
||||
my_hint_anwser = my_hint_anwser[:my_delimitor_index]
|
||||
#remove last char.
|
||||
remove_last_char_list = [')','(','.','。',')','(','[',']']
|
||||
for check_char in remove_last_char_list:
|
||||
if my_hint_anwser[-1:]==check_char:
|
||||
my_hint_anwser = my_hint_anwser[:-1]
|
||||
|
||||
my_anwser_formated = convert_string_to_pattern(my_hint_anwser, dynamic_length=False)
|
||||
#print("my_hint_anwser:", my_hint_anwser)
|
||||
#print(u"my_anwser_formated:", my_anwser_formated)
|
||||
if my_anwser_formated == u"[\\d][\\d][\\d][\\d][\\d][\\d][\\d][\\d]":
|
||||
my_datetime_foramted = "%Y%m%d"
|
||||
if my_anwser_formated == u"[\\d][\\d][\\d][\\d]/[\\d][\\d]/[\\d][\\d]":
|
||||
my_datetime_foramted = "%Y/%m/%d"
|
||||
|
||||
if show_debug_message:
|
||||
print("my_hint_anwser:", my_hint_anwser)
|
||||
print("my_anwser_formated:", my_anwser_formated)
|
||||
print("my_datetime_foramted:", my_datetime_foramted)
|
||||
break
|
||||
|
||||
if not my_datetime_foramted is None:
|
||||
|
@ -2104,14 +2150,16 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
if my_delimitor_symbol in web_datetime:
|
||||
web_datetime = web_datetime[:web_datetime.find(my_delimitor_symbol)]
|
||||
date_time = datetime.strptime(web_datetime,u"%Y/%m/%d")
|
||||
#print("date_time:", date_time)
|
||||
if show_debug_message:
|
||||
print("date_time:", date_time)
|
||||
ans = None
|
||||
try:
|
||||
ans = date_time.strftime(my_datetime_foramted)
|
||||
except Exception as exc:
|
||||
pass
|
||||
captcha_password_string = ans
|
||||
#print(u"my_anwser:", ans)
|
||||
if show_debug_message:
|
||||
print("my_anwser:", ans)
|
||||
|
||||
# parse '演出時間'
|
||||
is_need_parse_web_time = False
|
||||
|
@ -2179,12 +2227,12 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
#print(u"my_anwser_formated:", my_anwser_formated)
|
||||
if my_anwser_formated == u"[\\d][\\d][\\d][\\d]":
|
||||
my_datetime_foramted = "%H%M"
|
||||
if u'12小時制' in tmp_text:
|
||||
if u'12小時' in tmp_text:
|
||||
my_datetime_foramted = "%I%M"
|
||||
|
||||
if my_anwser_formated == u"[\\d][\\d]:[\\d][\\d]":
|
||||
my_datetime_foramted = "%H:%M"
|
||||
if u'12小時制' in tmp_text:
|
||||
if u'12小時' in tmp_text:
|
||||
my_datetime_foramted = "%I:%M"
|
||||
|
||||
if not my_datetime_foramted is None:
|
||||
|
@ -2239,7 +2287,9 @@ def kktix_reg_new_main(url, answer_index, registrationsNewApp_div, is_finish_che
|
|||
captcha_password_string = None
|
||||
#print("is_combine_two_question:", is_combine_two_question)
|
||||
|
||||
#print("captcha_password_string:", captcha_password_string)
|
||||
if show_debug_message:
|
||||
print("captcha_password_string:", captcha_password_string)
|
||||
|
||||
# ask question.
|
||||
if auto_guess_options:
|
||||
if not is_combine_two_question:
|
||||
|
@ -2448,7 +2498,7 @@ def kktix_reg_new(driver, url, answer_index, kktix_register_status_last):
|
|||
# PS: it seems use date_auto_select_mode instead of area_auto_select_mode
|
||||
def get_fami_target_area(date_keyword, area_keyword_1, area_keyword_2, area_auto_select_mode):
|
||||
show_debug_message = True # debug.
|
||||
show_debug_message = False # online
|
||||
#show_debug_message = False # online
|
||||
|
||||
areas = None
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import sys
|
|||
import platform
|
||||
import json
|
||||
|
||||
CONST_APP_VERSION = u"MaxBot (2022.09.19)"
|
||||
CONST_APP_VERSION = u"MaxBot (2022.10.19)"
|
||||
|
||||
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
|
||||
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
|
||||
|
|
Loading…
Reference in New Issue