From ad33e34891c3726351b62a14b76e4f55a69a3dfc Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Sep 2022 18:48:21 +0800 Subject: [PATCH] ver 2022.09.13 automatically download chromedrive, support google account sign in. --- chrome_tixcraft.py | 20 +++++++++++++++++--- settings.py | 20 +++++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/chrome_tixcraft.py b/chrome_tixcraft.py index bef2897..f861d1a 100644 --- a/chrome_tixcraft.py +++ b/chrome_tixcraft.py @@ -8,7 +8,7 @@ import random #print("python version", platform.python_version()) driver_type = 'stealth' -#driver_type = 'undetected_chromedriver' +driver_type = 'undetected_chromedriver' if driver_type=="undetected_chromedriver": from seleniumwire import webdriver @@ -60,7 +60,7 @@ ssl._create_default_https_context = ssl._create_unverified_context #附註1:沒有寫的很好,很多地方應該可以模組化。 #附註2: -CONST_APP_VERSION = u"MaxBot (2022.07.27)" +CONST_APP_VERSION = u"MaxBot (2022.09.13)" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top" @@ -429,6 +429,12 @@ def load_config_from_local(driver): # method 5: uc #options = webdriver.ChromeOptions() if driver_type=="undetected_chromedriver": + # multiprocessing not work bug. + if platform.system().lower()=="windows": + if hasattr(sys, 'frozen'): + from multiprocessing import freeze_support + freeze_support() + options = uc.ChromeOptions() options.add_argument("--password-store=basic") options.page_load_strategy="eager" @@ -440,13 +446,19 @@ def load_config_from_local(driver): driver = uc.Chrome(executable_path=chromedriver_path, options=options) else: print("Oops! web driver not on path:",chromedriver_path ) - driver = uc.Chrome(options=options, suppress_welcome=False) + print('let uc automatically download chromedriver.') + #driver = uc.Chrome(options=options, suppress_welcome=False) + driver = uc.Chrome(options=options) + + if driver is None: + print("create web drive object fail!") download_dir_path="." params = { "behavior": "allow", "downloadPath": os.path.realpath(download_dir_path) } + #print("assign setDownloadBehavior.") driver.execute_cdp_cmd("Page.setDownloadBehavior", params) @@ -459,7 +471,9 @@ def load_config_from_local(driver): firefox_service = Service(chromedriver_path) driver = webdriver.Firefox(service=firefox_service) + time.sleep(1.0) + #print("try to close opened tabs.") try: window_handles_count = len(driver.window_handles) if window_handles_count >= 1: diff --git a/settings.py b/settings.py index b2b2fdb..f080187 100644 --- a/settings.py +++ b/settings.py @@ -17,7 +17,7 @@ import sys import platform import json -CONST_APP_VERSION = u"MaxBot (2022.07.27)" +CONST_APP_VERSION = u"MaxBot (2022.09.13)" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top" @@ -153,8 +153,11 @@ def btn_save_act(slience_mode=False): return is_all_data_correct def btn_run_clicked(): + print('run button pressed.') Root_Dir = "" - if btn_save_act(slience_mode=True): + save_ret = btn_save_act(slience_mode=True) + print("save config result:", save_ret) + if save_ret: import subprocess if hasattr(sys, 'frozen'): print("execute in frozen mode") @@ -171,18 +174,25 @@ def btn_run_clicked(): print("execute .exe binary.") subprocess.Popen("chrome_tixcraft.exe", shell=True) else: - #print("execute in shell mode") + interpreter_binary = 'python' + interpreter_binary_alt = 'python3' + + print("execute in shell mode.") working_dir = os.path.dirname(os.path.realpath(__file__)) #print("script path:", working_dir) #messagebox.showinfo(title="Debug0", message=working_dir) + + # some python3 binary, running in 'python' command. try: - s=subprocess.Popen(['python3', 'chrome_tixcraft.py'], cwd=working_dir) + print('try', interpreter_binary) + s=subprocess.Popen([interpreter_binary, 'chrome_tixcraft.py'], cwd=working_dir) #s=subprocess.Popen(['./chrome_tixcraft'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=working_dir) #s=subprocess.run(['python3', 'chrome_tixcraft.py'], cwd=working_dir) #messagebox.showinfo(title="Debug1", message=str(s)) except Exception as exc: + print('try', interpreter_binary_alt) try: - s=subprocess.Popen(['python', 'chrome_tixcraft.py'], cwd=working_dir) + s=subprocess.Popen([interpreter_binary_alt, 'chrome_tixcraft.py'], cwd=working_dir) except Exception as exc: msg=str(exc) messagebox.showinfo(title="Debug2", message=msg)