Refactor load_chromdriver_normal function in chrome_tixcraft.py for improved code organization and error handling

master
Yong-Jer Chuang 2024-04-26 14:40:43 +08:00
parent 0c8a44c447
commit fa575ceea4
1 changed files with 3 additions and 12 deletions

View File

@ -315,11 +315,7 @@ def get_chrome_options(webdriver_path, config_dict):
return chrome_options return chrome_options
def load_chromdriver_normal(config_dict, driver_type): def load_chromdriver_normal(config_dict, driver_type):
show_debug_message = True # debug. show_debug_message = config_dict["advanced"]["verbose"]
show_debug_message = False # online
if config_dict["advanced"]["verbose"]:
show_debug_message = True
driver = None driver = None
@ -327,8 +323,7 @@ def load_chromdriver_normal(config_dict, driver_type):
webdriver_path = os.path.join(Root_Dir, "webdriver") webdriver_path = os.path.join(Root_Dir, "webdriver")
chromedriver_path = get_chromedriver_path(webdriver_path) chromedriver_path = get_chromedriver_path(webdriver_path)
if not os.path.exists(webdriver_path): os.makedirs(webdriver_path, exist_ok=True)
os.mkdir(webdriver_path)
if not os.path.exists(chromedriver_path): if not os.path.exists(chromedriver_path):
print("WebDriver not exist, try to download to:", webdriver_path) print("WebDriver not exist, try to download to:", webdriver_path)
@ -347,11 +342,7 @@ def load_chromdriver_normal(config_dict, driver_type):
error_message = str(exc) error_message = str(exc)
if show_debug_message: if show_debug_message:
print(exc) print(exc)
left_part = None left_part = error_message.split("Stacktrace:")[0] if "Stacktrace:" in error_message else 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: if "This version of ChromeDriver only supports Chrome version" in error_message:
print(CONST_CHROME_VERSION_NOT_MATCH_EN) print(CONST_CHROME_VERSION_NOT_MATCH_EN)
print(CONST_CHROME_VERSION_NOT_MATCH_TW) print(CONST_CHROME_VERSION_NOT_MATCH_TW)