2023-02-08, fix kham, hkticketing, fine tune error message.

master
CHUN YU YAO 2023-02-10 00:22:13 +08:00
parent bda5961ed1
commit 6c4de5bad8
2 changed files with 114 additions and 45 deletions

View File

@ -51,7 +51,7 @@ except Exception as exc:
import ssl import ssl
ssl._create_default_https_context = ssl._create_unverified_context ssl._create_default_https_context = ssl._create_unverified_context
CONST_APP_VERSION = u"MaxBot (2023.02.05)" CONST_APP_VERSION = u"MaxBot (2023.02.08)"
CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com" CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com"
@ -129,10 +129,10 @@ def get_chromedriver_path(webdriver_path):
chromedriver_path = os.path.join(webdriver_path,"chromedriver.exe") chromedriver_path = os.path.join(webdriver_path,"chromedriver.exe")
return chromedriver_path return chromedriver_path
def load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable): def get_chrome_options(webdriver_path, adblock_plus_enable, browser="chrome"):
chrome_options = webdriver.ChromeOptions() chrome_options = webdriver.ChromeOptions()
if browser=="edge":
chromedriver_path = get_chromedriver_path(webdriver_path) chrome_options = webdriver.EdgeOptions()
# some windows cause: timed out receiving message from renderer # some windows cause: timed out receiving message from renderer
if adblock_plus_enable: if adblock_plus_enable:
@ -166,10 +166,25 @@ def load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable):
#caps["unhandledPromptBehavior"] = u"dismiss" #caps["unhandledPromptBehavior"] = u"dismiss"
caps["unhandledPromptBehavior"] = u"accept" caps["unhandledPromptBehavior"] = u"accept"
chrome_service = Service(chromedriver_path) return chrome_options, caps
def load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable):
chromedriver_path = get_chromedriver_path(webdriver_path)
chrome_service = Service(chromedriver_path)
chrome_options, caps = get_chrome_options(webdriver_path, adblock_plus_enable)
driver = None
try:
# method 6: Selenium Stealth # method 6: Selenium Stealth
driver = webdriver.Chrome(service=chrome_service, options=chrome_options, desired_capabilities=caps) driver = webdriver.Chrome(service=chrome_service, options=chrome_options, desired_capabilities=caps)
except Exception as exc:
error_message = str(exc)
left_part = None
if "Stacktrace:" in error_message:
left_part = error_message.split("Stacktrace:")[0]
print(left_part)
if "This version of ChromeDriver only supports Chrome version" in error_message:
print("Please download the WebDriver version to match your browser version.")
if driver_type=="stealth": if driver_type=="stealth":
from selenium_stealth import stealth from selenium_stealth import stealth
@ -226,10 +241,16 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable):
try: try:
driver = uc.Chrome(executable_path=chromedriver_path, options=options, desired_capabilities=caps, suppress_welcome=False) driver = uc.Chrome(executable_path=chromedriver_path, options=options, desired_capabilities=caps, suppress_welcome=False)
except Exception as exc: except Exception as exc:
if "cannot connect to chrome" in str(exc): error_message = str(exc)
if "This version of ChromeDriver only supports Chrome version" in str(exc): left_part = None
if "Stacktrace:" in error_message:
left_part = error_message.split("Stacktrace:")[0]
print(left_part)
if "This version of ChromeDriver only supports Chrome version" in error_message:
print("Please download the WebDriver version to match your browser version.")
is_local_chrome_browser_lower = True is_local_chrome_browser_lower = True
print(exc) #print(exc)
pass pass
if is_local_chrome_browser_lower: if is_local_chrome_browser_lower:
@ -399,7 +420,15 @@ def get_driver_by_config(config_dict, driver_type):
chromedriver_path = os.path.join(webdriver_path,"geckodriver_arm") chromedriver_path = os.path.join(webdriver_path,"geckodriver_arm")
webdriver_service = Service(chromedriver_path) webdriver_service = Service(chromedriver_path)
driver = None
try:
driver = webdriver.Firefox(service=webdriver_service) driver = webdriver.Firefox(service=webdriver_service)
except Exception as exc:
error_message = str(exc)
left_part = None
if "Stacktrace:" in error_message:
left_part = error_message.split("Stacktrace:")[0]
print(left_part)
if browser == "edge": if browser == "edge":
# default os is linux/mac # default os is linux/mac
@ -409,7 +438,19 @@ def get_driver_by_config(config_dict, driver_type):
chromedriver_path = os.path.join(webdriver_path,"msedgedriver.exe") chromedriver_path = os.path.join(webdriver_path,"msedgedriver.exe")
webdriver_service = Service(chromedriver_path) webdriver_service = Service(chromedriver_path)
driver = webdriver.Edge(service=webdriver_service) chrome_options, caps = get_chrome_options(webdriver_path, adblock_plus_enable, browser="edge")
driver = None
try:
driver = webdriver.Edge(service=webdriver_service, options=chrome_options)
except Exception as exc:
error_message = str(exc)
#print(error_message)
left_part = None
if "Stacktrace:" in error_message:
left_part = error_message.split("Stacktrace:")[0]
print(left_part)
#print("try to close opened tabs.") #print("try to close opened tabs.")
''' '''
@ -977,7 +1018,7 @@ def tixcraft_home(driver):
try: try:
accept_all_cookies_btn.click() accept_all_cookies_btn.click()
except Exception as exc: except Exception as exc:
print("try to click accept_all_cookies_btn fail") print("try to click accept_all_cookies_btn fail, force click by js.")
try: try:
driver.execute_script("arguments[0].click();", accept_all_cookies_btn) driver.execute_script("arguments[0].click();", accept_all_cookies_btn)
except Exception as exc: except Exception as exc:
@ -1007,7 +1048,7 @@ def tixcraft_home(driver):
try: try:
alert_btn.click() alert_btn.click()
except Exception as exc: except Exception as exc:
print("try to click alert_btn fail") print("try to click alert_btn fail, force click by js.")
try: try:
driver.execute_script("arguments[0].click();", alert_btn) driver.execute_script("arguments[0].click();", alert_btn)
except Exception as exc: except Exception as exc:
@ -1036,7 +1077,7 @@ def tixcraft_redirect(driver, url):
return ret return ret
def tixcraft_date_auto_select(driver, url, config_dict): def tixcraft_date_auto_select(driver, url, config_dict, domain_name):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
@ -1164,14 +1205,26 @@ def tixcraft_date_auto_select(driver, url, config_dict):
target_row_index = random.randint(0,len(button_list)-1) target_row_index = random.randint(0,len(button_list)-1)
if show_debug_message: if show_debug_message:
print("clicking row:", target_row_index+1) print("clicking at button index:", target_row_index+1)
el = None
try: try:
el = button_list[target_row_index] el = button_list[target_row_index]
if show_debug_message:
print("pressing button...")
el.click() el.click()
'''
ticket_url = el.get_attribute('data-href')
is_redirected = False
if not ticket_url is None:
if len(ticket_url) > 0:
driver.get("https:%s%s" % (domain_name, ticket_url))
is_redirected = True
'''
is_date_selected = True is_date_selected = True
except Exception as exc: except Exception as exc:
print("try to click .btn-next fail") print("try to click .btn-next fail, force click by js.")
print(exc)
try: try:
driver.execute_script("arguments[0].click();", el) driver.execute_script("arguments[0].click();", el)
except Exception as exc: except Exception as exc:
@ -1184,6 +1237,9 @@ def tixcraft_date_auto_select(driver, url, config_dict):
# [PS]: current reload condition only when # [PS]: current reload condition only when
if auto_reload_coming_soon_page_enable: if auto_reload_coming_soon_page_enable:
if is_coming_soon: if is_coming_soon:
if show_debug_message:
print("match is_coming_soon, start to reload page.")
# case 2: match one row is coming soon. # case 2: match one row is coming soon.
try: try:
driver.refresh() driver.refresh()
@ -2082,7 +2138,7 @@ def kktix_captcha_text_value(captcha_inner_div):
def kktix_input_captcha_text(captcha_password_input_tag, inferred_answer_string, force_overwrite = False): def kktix_input_captcha_text(captcha_password_input_tag, inferred_answer_string, force_overwrite = False):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
is_cpatcha_sent = False is_cpatcha_sent = False
inputed_captcha_text = "" inputed_captcha_text = ""
@ -3840,7 +3896,7 @@ def urbtix_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_
def urbtix_ticket_number_auto_select(driver, ticket_number): def urbtix_ticket_number_auto_select(driver, ticket_number):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online show_debug_message = False # online
is_ticket_number_assigned = False is_ticket_number_assigned = False
ticket_number_str = str(ticket_number) ticket_number_str = str(ticket_number)
@ -5269,7 +5325,6 @@ def tixcraft_main(driver, url, config_dict, is_verifyCode_editing, ocr, Captcha_
if not Captcha_Browser is None: if not Captcha_Browser is None:
Captcha_Browser.Set_cookies(driver.get_cookies()) Captcha_Browser.Set_cookies(driver.get_cookies())
Captcha_Browser.Set_Domain(domain_name) Captcha_Browser.Set_Domain(domain_name)
break break
if "/activity/detail/" in url: if "/activity/detail/" in url:
@ -5279,7 +5334,8 @@ def tixcraft_main(driver, url, config_dict, is_verifyCode_editing, ocr, Captcha_
if "/activity/game/" in url: if "/activity/game/" in url:
date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"] date_auto_select_enable = config_dict["tixcraft"]["date_auto_select"]["enable"]
if date_auto_select_enable: if date_auto_select_enable:
is_date_selected = tixcraft_date_auto_select(driver, url, config_dict) domain_name = url.split('/')[2]
is_date_selected = tixcraft_date_auto_select(driver, url, config_dict, domain_name)
# choose area # choose area
if '/ticket/area/' in url: if '/ticket/area/' in url:
@ -6332,6 +6388,10 @@ def hkticketing_main(driver, url, config_dict):
#https://premier.hkticketing.com/shows/show.aspx?sh=XXXX #https://premier.hkticketing.com/shows/show.aspx?sh=XXXX
if 'shows/show.aspx?' in url: if 'shows/show.aspx?' in url:
is_modal_dialog_popup = check_modal_dialog_popup(driver)
if is_modal_dialog_popup:
print("is_modal_dialog_popup! skip...")
else:
is_event_page = False is_event_page = False
if len(url.split('/'))==5: if len(url.split('/'))==5:
is_event_page = True is_event_page = True
@ -6346,6 +6406,10 @@ def hkticketing_main(driver, url, config_dict):
if '/events/' in url and '/performances/' in url: if '/events/' in url and '/performances/' in url:
robot_detection = hkticketing_escape_robot_detection(driver) robot_detection = hkticketing_escape_robot_detection(driver)
is_modal_dialog_popup = check_modal_dialog_popup(driver)
if is_modal_dialog_popup:
print("is_modal_dialog_popup! skip...")
else:
if '/tickets' in url: if '/tickets' in url:
domain_name = url.split('/')[2] domain_name = url.split('/')[2]
area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"] area_auto_select_enable = config_dict["tixcraft"]["area_auto_select"]["enable"]
@ -6617,9 +6681,14 @@ def kham_area_auto_select(driver, area_auto_select_mode, area_keyword_1, area_ke
my_css_selector = "span.textPrice" my_css_selector = "span.textPrice"
el_remaining = row.find_element(By.CSS_SELECTOR, my_css_selector) el_remaining = row.find_element(By.CSS_SELECTOR, my_css_selector)
if el_remaining is not None: if el_remaining is not None:
remaining_value = str(el_remaining.text) remaining_value = str(el_remaining.text).strip()
if remaining_value.isnumeric():
if int(remaining_value) >= ticket_number: if int(remaining_value) >= ticket_number:
row_is_enabled=True row_is_enabled=True
else:
# text directly allow.
row_is_enabled=True
except Exception as exc: except Exception as exc:
pass pass

View File

@ -19,7 +19,7 @@ import json
import webbrowser import webbrowser
import pyperclip import pyperclip
CONST_APP_VERSION = u"MaxBot (2023.02.06)" CONST_APP_VERSION = u"MaxBot (2023.02.08)"
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top" CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
@ -1099,11 +1099,11 @@ def PreferenctTab(root, config_dict, language_code, UI_PADDING_X):
,"https://kham.com.tw/ (寬宏)" ,"https://kham.com.tw/ (寬宏)"
,"http://www.urbtix.hk/ (城市)" ,"http://www.urbtix.hk/ (城市)"
,"https://www.cityline.com/ (買飛)" ,"https://www.cityline.com/ (買飛)"
,"https://premier.hkticketing.com/ (快達票)"
,"https://ticketing.galaxymacau.com/ (澳門銀河)" ,"https://ticketing.galaxymacau.com/ (澳門銀河)"
] ]
# 目前機器人已失效, 因為官方的 reCaptcha 可以檢測出機器人。 # 目前機器人已失效, 因為官方的 reCaptcha 可以檢測出機器人。
''' '''
,"https://premier.hkticketing.com/ (快達票)"
''' '''
combo_homepage.set(homepage) combo_homepage.set(homepage)
combo_homepage.bind("<<ComboboxSelected>>", callbackHomepageOnChange) combo_homepage.bind("<<ComboboxSelected>>", callbackHomepageOnChange)