output load chrome driver exception by check config options.
parent
24b366ffdc
commit
0d32ef04d4
|
@ -357,10 +357,23 @@ def get_chrome_options(webdriver_path, adblock_plus_enable, browser="chrome", he
|
||||||
|
|
||||||
return chrome_options, caps
|
return chrome_options, caps
|
||||||
|
|
||||||
def load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable, headless):
|
def load_chromdriver_normal(config_dict, driver_type):
|
||||||
|
show_debug_message = True # debug.
|
||||||
|
show_debug_message = False # online
|
||||||
|
|
||||||
|
if config_dict["advanced"]["verbose"]:
|
||||||
|
show_debug_message = True
|
||||||
|
|
||||||
driver = None
|
driver = None
|
||||||
|
|
||||||
|
Root_Dir = get_app_root()
|
||||||
|
webdriver_path = os.path.join(Root_Dir, "webdriver")
|
||||||
|
|
||||||
|
adblock_plus_enable = config_dict["advanced"]["adblock_plus_enable"]
|
||||||
|
headless = config_dict["advanced"]["headless"]
|
||||||
|
|
||||||
chromedriver_path = get_chromedriver_path(webdriver_path)
|
chromedriver_path = get_chromedriver_path(webdriver_path)
|
||||||
|
|
||||||
if not os.path.exists(chromedriver_path):
|
if not os.path.exists(chromedriver_path):
|
||||||
print("Please download chromedriver and extract zip to webdriver folder from this url:")
|
print("Please download chromedriver and extract zip to webdriver folder from this url:")
|
||||||
print("請下在面的網址下載與你chrome瀏覽器相同版本的chromedriver,解壓縮後放到webdriver目錄裡:")
|
print("請下在面的網址下載與你chrome瀏覽器相同版本的chromedriver,解壓縮後放到webdriver目錄裡:")
|
||||||
|
@ -373,6 +386,8 @@ def load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable, he
|
||||||
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:
|
except Exception as exc:
|
||||||
error_message = str(exc)
|
error_message = str(exc)
|
||||||
|
if show_debug_message:
|
||||||
|
print(exc)
|
||||||
left_part = None
|
left_part = None
|
||||||
if "Stacktrace:" in error_message:
|
if "Stacktrace:" in error_message:
|
||||||
left_part = error_message.split("Stacktrace:")[0]
|
left_part = error_message.split("Stacktrace:")[0]
|
||||||
|
@ -397,7 +412,18 @@ def load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable, he
|
||||||
|
|
||||||
return driver
|
return driver
|
||||||
|
|
||||||
def load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless):
|
def load_chromdriver_uc(config_dict):
|
||||||
|
show_debug_message = True # debug.
|
||||||
|
show_debug_message = False # online
|
||||||
|
|
||||||
|
if config_dict["advanced"]["verbose"]:
|
||||||
|
show_debug_message = True
|
||||||
|
|
||||||
|
Root_Dir = get_app_root()
|
||||||
|
webdriver_path = os.path.join(Root_Dir, "webdriver")
|
||||||
|
adblock_plus_enable = config_dict["advanced"]["adblock_plus_enable"]
|
||||||
|
headless = config_dict["advanced"]["headless"]
|
||||||
|
|
||||||
import undetected_chromedriver as uc
|
import undetected_chromedriver as uc
|
||||||
|
|
||||||
chromedriver_path = get_chromedriver_path(webdriver_path)
|
chromedriver_path = get_chromedriver_path(webdriver_path)
|
||||||
|
@ -443,7 +469,8 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless):
|
||||||
driver = uc.Chrome(driver_executable_path=chromedriver_path, options=options, desired_capabilities=caps)
|
driver = uc.Chrome(driver_executable_path=chromedriver_path, options=options, desired_capabilities=caps)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
error_message = str(exc)
|
error_message = str(exc)
|
||||||
#print(exc)
|
if show_debug_message:
|
||||||
|
print(exc)
|
||||||
left_part = None
|
left_part = None
|
||||||
if "Stacktrace:" in error_message:
|
if "Stacktrace:" in error_message:
|
||||||
left_part = error_message.split("Stacktrace:")[0]
|
left_part = error_message.split("Stacktrace:")[0]
|
||||||
|
@ -460,7 +487,8 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless):
|
||||||
driver = uc.Chrome(options=options, desired_capabilities=caps)
|
driver = uc.Chrome(options=options, desired_capabilities=caps)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
error_message = str(exc)
|
error_message = str(exc)
|
||||||
#print(exc)
|
if show_debug_message:
|
||||||
|
print(exc)
|
||||||
left_part = None
|
left_part = None
|
||||||
if "Stacktrace:" in error_message:
|
if "Stacktrace:" in error_message:
|
||||||
left_part = error_message.split("Stacktrace:")[0]
|
left_part = error_message.split("Stacktrace:")[0]
|
||||||
|
@ -478,7 +506,7 @@ def load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless):
|
||||||
print("Unable to use undetected_chromedriver, ")
|
print("Unable to use undetected_chromedriver, ")
|
||||||
print("try to use local chromedriver to launch chrome browser.")
|
print("try to use local chromedriver to launch chrome browser.")
|
||||||
driver_type = "selenium"
|
driver_type = "selenium"
|
||||||
driver = load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable, headless)
|
driver = load_chromdriver_normal(config_dict, driver_type)
|
||||||
else:
|
else:
|
||||||
print("建議您自行下載 ChromeDriver 到 webdriver 的資料夾下")
|
print("建議您自行下載 ChromeDriver 到 webdriver 的資料夾下")
|
||||||
print("you need manually download ChromeDriver to webdriver folder.")
|
print("you need manually download ChromeDriver to webdriver folder.")
|
||||||
|
@ -538,7 +566,7 @@ def get_driver_by_config(config_dict):
|
||||||
if browser == "chrome":
|
if browser == "chrome":
|
||||||
# method 6: Selenium Stealth
|
# method 6: Selenium Stealth
|
||||||
if driver_type != CONST_WEBDRIVER_TYPE_UC:
|
if driver_type != CONST_WEBDRIVER_TYPE_UC:
|
||||||
driver = load_chromdriver_normal(webdriver_path, driver_type, adblock_plus_enable, headless)
|
driver = load_chromdriver_normal(config_dict, driver_type)
|
||||||
else:
|
else:
|
||||||
# method 5: uc
|
# method 5: uc
|
||||||
# multiprocessing not work bug.
|
# multiprocessing not work bug.
|
||||||
|
@ -546,7 +574,7 @@ def get_driver_by_config(config_dict):
|
||||||
if hasattr(sys, 'frozen'):
|
if hasattr(sys, 'frozen'):
|
||||||
from multiprocessing import freeze_support
|
from multiprocessing import freeze_support
|
||||||
freeze_support()
|
freeze_support()
|
||||||
driver = load_chromdriver_uc(webdriver_path, adblock_plus_enable, headless)
|
driver = load_chromdriver_uc(config_dict)
|
||||||
|
|
||||||
if browser == "firefox":
|
if browser == "firefox":
|
||||||
# default os is linux/mac
|
# default os is linux/mac
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"homepage": "https://tixcraft.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "pass_1_seat_remaining": true, "auto_check_agree": true, "ocr_captcha": {"enable": true, "force_submit": true, "image_source": "canvas"}, "webdriver_type": "undetected_chromedriver", "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true, "user_guess_string": ""}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "from top to bottom"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true, "presale_code": "", "presale_code_delimiter": ""}, "area_auto_select": {"enable": true, "mode": "from top to bottom", "area_keyword": "", "area_keyword_exclude": "\"\u8f2a\u6905\",\"\u8eab\u969c\",\"\u8eab\u5fc3\u969c\u7919\""}, "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "tixcraft_sid": "", "ibonqware": "", "facebook_account": "", "kktix_account": "", "cityline_account": "", "urbtix_account": "", "hkticketing_account": "", "kham_account": "", "facebook_password": "", "kktix_password": "", "cityline_password": "", "urbtix_password": "", "hkticketing_password": "", "kham_password": "", "adblock_plus_enable": false, "disable_adjacent_seat": false, "headless": false, "verbose": false, "auto_guess_options": false, "auto_reload_page_interval": 2.0}}
|
{"homepage": "https://tixcraft.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "pass_1_seat_remaining": true, "auto_check_agree": true, "ocr_captcha": {"enable": true, "force_submit": true, "image_source": "canvas"}, "webdriver_type": "undetected_chromedriver", "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true, "user_guess_string": ""}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "from top to bottom"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true, "presale_code": "", "presale_code_delimiter": ""}, "area_auto_select": {"enable": true, "mode": "from top to bottom", "area_keyword": "", "area_keyword_exclude": "\"\u8f2a\u6905\",\"\u8eab\u969c\",\"\u8eab\u5fc3 \u969c\u7919\""}, "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "tixcraft_sid": "", "ibonqware": "", "facebook_account": "", "kktix_account": "", "cityline_account": "", "urbtix_account": "", "hkticketing_account": "", "kham_account": "", "facebook_password": "", "kktix_password": "", "cityline_password": "", "urbtix_password": "", "hkticketing_password": "", "kham_password": "", "adblock_plus_enable": false, "disable_adjacent_seat": false, "headless": false, "verbose": false, "auto_guess_options": false, "auto_reload_page_interval": 2.0}}
|
|
@ -517,7 +517,7 @@ def get_default_config():
|
||||||
config_dict["area_auto_select"]["enable"] = True
|
config_dict["area_auto_select"]["enable"] = True
|
||||||
config_dict["area_auto_select"]["mode"] = CONST_SELECT_ORDER_DEFAULT
|
config_dict["area_auto_select"]["mode"] = CONST_SELECT_ORDER_DEFAULT
|
||||||
config_dict["area_auto_select"]["area_keyword"] = ""
|
config_dict["area_auto_select"]["area_keyword"] = ""
|
||||||
config_dict["area_auto_select"]["area_keyword_exclude"] = "\"輪椅\",\"身障\",\"身心障礙\""
|
config_dict["area_auto_select"]["area_keyword_exclude"] = "\"輪椅\",\"身障\",\"身心 障礙\""
|
||||||
|
|
||||||
config_dict["tixcraft"]["pass_date_is_sold_out"] = True
|
config_dict["tixcraft"]["pass_date_is_sold_out"] = True
|
||||||
config_dict["tixcraft"]["auto_reload_coming_soon_page"] = True
|
config_dict["tixcraft"]["auto_reload_coming_soon_page"] = True
|
||||||
|
|
Loading…
Reference in New Issue