reload page by client side javascript if ticket sold out.

master
Max 2023-11-03 12:13:15 +08:00 committed by GitHub
parent 3112ca81cf
commit 40f021ff9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -55,7 +55,7 @@ import webbrowser
import chromedriver_autoinstaller import chromedriver_autoinstaller
CONST_APP_VERSION = "MaxBot (2023.10.23)" CONST_APP_VERSION = "MaxBot (2023.11.01)"
CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_CONFIG_FILE = "settings.json"
CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt"
@ -780,6 +780,9 @@ def get_driver_by_config(config_dict):
print("create web driver object fail @_@;") print("create web driver object fail @_@;")
else: else:
try: try:
NETWORK_BLOCKED_URLS = ['*woff2','*woff','*google-analytics.*','*googletagmanager.*','*googletagservices.*','*youtube.com*','*player.youku.*','*e2elog.fetnet.net*']
driver.execute_cdp_cmd('Network.setBlockedURLs', {"urls": NETWORK_BLOCKED_URLS})
driver.execute_cdp_cmd('Network.enable', {})
if 'kktix.c' in homepage: if 'kktix.c' in homepage:
if len(config_dict["advanced"]["kktix_account"])>0: if len(config_dict["advanced"]["kktix_account"])>0:
if not 'https://kktix.com/users/sign_in?' in homepage: if not 'https://kktix.com/users/sign_in?' in homepage:
@ -1559,7 +1562,7 @@ def force_press_button_iframe(driver, f, select_by, select_query, force_submit=T
return is_clicked return is_clicked
def clean_tag_by_selector(driver, select_query): def clean_tag_by_selector(driver, select_query, more_script = ""):
try: try:
driver.set_script_timeout(1) driver.set_script_timeout(1)
js = """var selectSoldoutItems = document.querySelectorAll('%s'); js = """var selectSoldoutItems = document.querySelectorAll('%s');
@ -1567,11 +1570,14 @@ selectSoldoutItems.forEach((userItem) =>
{ {
userItem.outerHTML=""; userItem.outerHTML="";
} }
);""" % select_query );
%s""" % (select_query, more_script)
#print("javascript:", js)
driver.execute_script(js) driver.execute_script(js)
ret = True ret = True
except Exception as exc: except Exception as exc:
#print(exc)
pass pass
def force_press_button(driver, select_by, select_query, force_submit=True): def force_press_button(driver, select_by, select_query, force_submit=True):
@ -9985,8 +9991,9 @@ def kham_area_auto_select(driver, domain_name, config_dict, area_keyword_item):
row_index += 1 row_index += 1
formated_area_list.append(row) formated_area_list.append(row)
else: else:
print("area list is empty, do refresh!") print("area list is empty, do refresh by javascript!")
is_need_refresh = True #is_need_refresh = True
pass
else: else:
if show_debug_message: if show_debug_message:
print("area_list_count is None.") print("area_list_count is None.")
@ -10717,7 +10724,10 @@ def kham_main(driver, url, config_dict, ocr, Captcha_Browser):
if "kham.com.tw" in url: if "kham.com.tw" in url:
select_query = "tr.Soldout" select_query = "tr.Soldout"
clean_tag_by_selector(driver,select_query) more_script = """var ticketItems = document.querySelectorAll('tr.status_tr');
if(ticketItems.length==0) { location.reload(); }
"""
clean_tag_by_selector(driver, select_query, more_script)
is_price_assign_by_bot, is_captcha_sent = kham_performance(driver, config_dict, ocr, Captcha_Browser, domain_name, model_name) is_price_assign_by_bot, is_captcha_sent = kham_performance(driver, config_dict, ocr, Captcha_Browser, domain_name, model_name)