2023-02-26, fix for hkticketing, but now MaxBot is detected by hkticketing...

master
CHUN YU YAO 2023-02-28 01:45:36 +08:00
parent b2f088b38d
commit 5780aa5225
2 changed files with 49 additions and 25 deletions

View File

@ -53,7 +53,7 @@ import argparse
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.25)" CONST_APP_VERSION = u"MaxBot (2023.02.26)"
CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com" CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com"
URL_GOOGLE_OAUTH = 'https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=email&access_type=offline&flowName=GeneralOAuthFlow' URL_GOOGLE_OAUTH = 'https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=email&access_type=offline&flowName=GeneralOAuthFlow'
@ -6265,9 +6265,10 @@ def hkticketing_home(driver):
show_debug_message = True # debug. show_debug_message = True # debug.
show_debug_message = False # online show_debug_message = False # online
is_hotshow_popup = False # OMG, I forgot why I wrote this code.
'''
body_iframe = None body_iframe = None
body_iframe_list = None
try: try:
body_iframe_list = driver.find_elements(By.CSS_SELECTOR, 'body > iframe') body_iframe_list = driver.find_elements(By.CSS_SELECTOR, 'body > iframe')
except Exception as exc: except Exception as exc:
@ -6285,26 +6286,25 @@ def hkticketing_home(driver):
hotshow_btn = driver.find_element(By.CSS_SELECTOR, 'div.hotshow > a.btn') hotshow_btn = driver.find_element(By.CSS_SELECTOR, 'div.hotshow > a.btn')
if hotshow_btn is not None: if hotshow_btn is not None:
if hotshow_btn.is_enabled() and hotshow_btn.is_displayed(): if hotshow_btn.is_enabled() and hotshow_btn.is_displayed():
is_hotshow_popup = True hotshow_btn.click()
driver.switch_to.default_content()
except Exception as exc: except Exception as exc:
pass
if show_debug_message: if show_debug_message:
print("find hotshow btn fail:", exc) print("find hotshow btn fail:", exc)
driver.switch_to.default_content() driver.switch_to.default_content()
'''
if show_debug_message: def hkticketing_accept_cookie(driver):
print("is_hotshow_popup", is_hotshow_popup) show_debug_message = True # debug.
show_debug_message = False # online
accept_all_cookies_btn = None accept_all_cookies_btn = None
if not is_hotshow_popup: try:
try: accept_all_cookies_btn = driver.find_element(By.ID, 'closepolicy_new')
accept_all_cookies_btn = driver.find_element(By.ID, 'closepolicy_new') except Exception as exc:
except Exception as exc: if show_debug_message:
if show_debug_message: print("find closepolicy_new fail")
print("find closepolicy_new fail") pass
pass
else:
print("reCaptcha popup, do nothing.")
if accept_all_cookies_btn is not None: if accept_all_cookies_btn is not None:
is_visible = False is_visible = False
@ -6320,11 +6320,14 @@ def hkticketing_home(driver):
try: try:
accept_all_cookies_btn.click() accept_all_cookies_btn.click()
except Exception as exc: except Exception as exc:
pass
'''
print("try to click closepolicy_new fail") print("try to click closepolicy_new fail")
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:
pass pass
'''
else: else:
if show_debug_message: if show_debug_message:
print("closepolicy_new invisible.") print("closepolicy_new invisible.")
@ -6344,7 +6347,7 @@ def hkticketing_date_auto_select(driver, auto_select_mode, date_keyword, auto_re
try: try:
form_select = driver.find_element(By.CSS_SELECTOR, '#p') form_select = driver.find_element(By.CSS_SELECTOR, '#p')
except Exception as exc: except Exception as exc:
print("find select fail") print("find select#p fail")
pass pass
select_obj = None select_obj = None
@ -6379,6 +6382,7 @@ def hkticketing_date_auto_select(driver, auto_select_mode, date_keyword, auto_re
#PS: some blocks are generate by ajax, not appear at first time. #PS: some blocks are generate by ajax, not appear at first time.
formated_area_list = None formated_area_list = None
is_page_ready = True
if not is_date_assigned: if not is_date_assigned:
area_list = None area_list = None
try: try:
@ -6393,7 +6397,9 @@ def hkticketing_date_auto_select(driver, auto_select_mode, date_keyword, auto_re
if show_debug_message: if show_debug_message:
print("date_list_count:", area_list_count) print("date_list_count:", area_list_count)
if area_list_count > 0: if area_list_count == 0:
is_page_ready = False
else:
formated_area_list = [] formated_area_list = []
# filter list. # filter list.
@ -6404,11 +6410,16 @@ def hkticketing_date_auto_select(driver, auto_select_mode, date_keyword, auto_re
option_value_string = None option_value_string = None
try: try:
if row.is_enabled(): if row.is_enabled():
'''
option_value_string = str(row.get_attribute('value')) option_value_string = str(row.get_attribute('value'))
if len(option_value_string) > 4: if len(option_value_string) > 6:
row_is_enabled=True row_is_enabled=True
'''
# alway disable. # alway disable.
option_text_string = str(row.text) option_text_string = str(row.text)
print("option_text_string:", option_text_string)
if '20' in option_text_string:
row_is_enabled=True
if ' Exhausted' in option_text_string: if ' Exhausted' in option_text_string:
row_is_enabled=False row_is_enabled=False
if '配售完畢' in option_text_string: if '配售完畢' in option_text_string:
@ -6519,6 +6530,9 @@ def hkticketing_date_auto_select(driver, auto_select_mode, date_keyword, auto_re
if target_area.is_enabled(): if target_area.is_enabled():
target_area.click() target_area.click()
is_date_assigned = True is_date_assigned = True
#PS:must delay here, due to next loop coming to soon, will cause refresh.
time.sleep(0.5)
except Exception as exc: except Exception as exc:
print("click target_area link fail") print("click target_area link fail")
print(exc) print(exc)
@ -6570,8 +6584,14 @@ def hkticketing_date_auto_select(driver, auto_select_mode, date_keyword, auto_re
# option waiting to assign at next loop. # option waiting to assign at next loop.
is_need_refresh = False is_need_refresh = False
# due to select option not generated by server side.
if is_need_refresh:
if not is_page_ready:
is_need_refresh = False
if is_need_refresh: if is_need_refresh:
try: try:
print("is_need_refresh...")
driver.refresh() driver.refresh()
time.sleep(0.3) time.sleep(0.3)
except Exception as exc: except Exception as exc:
@ -6994,10 +7014,13 @@ def hkticketing_escape_robot_detection(driver):
pass pass
if el_main_iframe is not None: if el_main_iframe is not None:
print("bingo, found el_main_iframe, start to escape") print("we have been detected..., found el_main_iframe")
entry_url="https://queue.hkticketing.com/hotshow.html" #entry_url="https://queue.hkticketing.com/hotshow.html"
entry_url="https://premier.hkticketing.com/"
try: try:
driver.get(entry_url) #print("start to escape..")
#driver.get(entry_url)
pass
except Exception as exc: except Exception as exc:
print(exc) print(exc)
@ -7015,9 +7038,10 @@ def hkticketing_main(driver, url, config_dict):
for each_url in home_url_list: for each_url in home_url_list:
if each_url == url: if each_url == url:
hkticketing_home(driver) hkticketing_home(driver)
time.sleep(0.2)
break break
hkticketing_accept_cookie(driver)
if 'queue.hkticketing.com/hotshow.html' in url: if 'queue.hkticketing.com/hotshow.html' in url:
entry_url = 'http://entry-hotshow.hkticketing.com/' entry_url = 'http://entry-hotshow.hkticketing.com/'
try: try:

View File

@ -20,7 +20,7 @@ import webbrowser
import pyperclip import pyperclip
import base64 import base64
CONST_APP_VERSION = u"MaxBot (2023.02.25)" CONST_APP_VERSION = u"MaxBot (2023.02.26)"
CONST_SETTINGS_CONFIG_FILENAME = "settings.json" CONST_SETTINGS_CONFIG_FILENAME = "settings.json"