ver 2022.09.13 automatically download chromedrive, support google account sign in.
parent
c145d588ee
commit
ad33e34891
|
@ -8,7 +8,7 @@ import random
|
||||||
#print("python version", platform.python_version())
|
#print("python version", platform.python_version())
|
||||||
|
|
||||||
driver_type = 'stealth'
|
driver_type = 'stealth'
|
||||||
#driver_type = 'undetected_chromedriver'
|
driver_type = 'undetected_chromedriver'
|
||||||
|
|
||||||
if driver_type=="undetected_chromedriver":
|
if driver_type=="undetected_chromedriver":
|
||||||
from seleniumwire import webdriver
|
from seleniumwire import webdriver
|
||||||
|
@ -60,7 +60,7 @@ ssl._create_default_https_context = ssl._create_unverified_context
|
||||||
#附註1:沒有寫的很好,很多地方應該可以模組化。
|
#附註1:沒有寫的很好,很多地方應該可以模組化。
|
||||||
#附註2:
|
#附註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_TOP_TO_BOTTOM = u"from top to bottom"
|
||||||
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
|
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
|
||||||
|
@ -429,6 +429,12 @@ def load_config_from_local(driver):
|
||||||
# method 5: uc
|
# method 5: uc
|
||||||
#options = webdriver.ChromeOptions()
|
#options = webdriver.ChromeOptions()
|
||||||
if driver_type=="undetected_chromedriver":
|
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 = uc.ChromeOptions()
|
||||||
options.add_argument("--password-store=basic")
|
options.add_argument("--password-store=basic")
|
||||||
options.page_load_strategy="eager"
|
options.page_load_strategy="eager"
|
||||||
|
@ -440,13 +446,19 @@ def load_config_from_local(driver):
|
||||||
driver = uc.Chrome(executable_path=chromedriver_path, options=options)
|
driver = uc.Chrome(executable_path=chromedriver_path, options=options)
|
||||||
else:
|
else:
|
||||||
print("Oops! web driver not on path:",chromedriver_path )
|
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="."
|
download_dir_path="."
|
||||||
params = {
|
params = {
|
||||||
"behavior": "allow",
|
"behavior": "allow",
|
||||||
"downloadPath": os.path.realpath(download_dir_path)
|
"downloadPath": os.path.realpath(download_dir_path)
|
||||||
}
|
}
|
||||||
|
#print("assign setDownloadBehavior.")
|
||||||
driver.execute_cdp_cmd("Page.setDownloadBehavior", params)
|
driver.execute_cdp_cmd("Page.setDownloadBehavior", params)
|
||||||
|
|
||||||
|
|
||||||
|
@ -459,7 +471,9 @@ def load_config_from_local(driver):
|
||||||
firefox_service = Service(chromedriver_path)
|
firefox_service = Service(chromedriver_path)
|
||||||
driver = webdriver.Firefox(service=firefox_service)
|
driver = webdriver.Firefox(service=firefox_service)
|
||||||
|
|
||||||
|
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
|
#print("try to close opened tabs.")
|
||||||
try:
|
try:
|
||||||
window_handles_count = len(driver.window_handles)
|
window_handles_count = len(driver.window_handles)
|
||||||
if window_handles_count >= 1:
|
if window_handles_count >= 1:
|
||||||
|
|
20
settings.py
20
settings.py
|
@ -17,7 +17,7 @@ import sys
|
||||||
import platform
|
import platform
|
||||||
import json
|
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_TOP_TO_BOTTOM = u"from top to bottom"
|
||||||
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
|
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
|
return is_all_data_correct
|
||||||
|
|
||||||
def btn_run_clicked():
|
def btn_run_clicked():
|
||||||
|
print('run button pressed.')
|
||||||
Root_Dir = ""
|
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
|
import subprocess
|
||||||
if hasattr(sys, 'frozen'):
|
if hasattr(sys, 'frozen'):
|
||||||
print("execute in frozen mode")
|
print("execute in frozen mode")
|
||||||
|
@ -171,18 +174,25 @@ def btn_run_clicked():
|
||||||
print("execute .exe binary.")
|
print("execute .exe binary.")
|
||||||
subprocess.Popen("chrome_tixcraft.exe", shell=True)
|
subprocess.Popen("chrome_tixcraft.exe", shell=True)
|
||||||
else:
|
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__))
|
working_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
#print("script path:", working_dir)
|
#print("script path:", working_dir)
|
||||||
#messagebox.showinfo(title="Debug0", message=working_dir)
|
#messagebox.showinfo(title="Debug0", message=working_dir)
|
||||||
|
|
||||||
|
# some python3 binary, running in 'python' command.
|
||||||
try:
|
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.Popen(['./chrome_tixcraft'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=working_dir)
|
||||||
#s=subprocess.run(['python3', 'chrome_tixcraft.py'], cwd=working_dir)
|
#s=subprocess.run(['python3', 'chrome_tixcraft.py'], cwd=working_dir)
|
||||||
#messagebox.showinfo(title="Debug1", message=str(s))
|
#messagebox.showinfo(title="Debug1", message=str(s))
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
print('try', interpreter_binary_alt)
|
||||||
try:
|
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:
|
except Exception as exc:
|
||||||
msg=str(exc)
|
msg=str(exc)
|
||||||
messagebox.showinfo(title="Debug2", message=msg)
|
messagebox.showinfo(title="Debug2", message=msg)
|
||||||
|
|
Loading…
Reference in New Issue