remove some not necessary codes.

master
Max 2023-08-03 14:26:30 +08:00 committed by GitHub
parent 264bb34137
commit 5c690d03a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 67 deletions

View File

@ -52,7 +52,6 @@ except Exception as exc:
import webbrowser import webbrowser
import argparse import argparse
import itertools
import chromedriver_autoinstaller import chromedriver_autoinstaller
CONST_APP_VERSION = "MaxBot (2023.07.23)" CONST_APP_VERSION = "MaxBot (2023.07.23)"
@ -85,7 +84,6 @@ CONST_OCR_CAPTCH_IMAGE_SOURCE_NON_BROWSER = "NonBrowser"
CONST_OCR_CAPTCH_IMAGE_SOURCE_CANVAS = "canvas" CONST_OCR_CAPTCH_IMAGE_SOURCE_CANVAS = "canvas"
CONST_WEBDRIVER_TYPE_SELENIUM = "selenium" CONST_WEBDRIVER_TYPE_SELENIUM = "selenium"
#CONST_WEBDRIVER_TYPE_STEALTH = "stealth"
CONST_WEBDRIVER_TYPE_UC = "undetected_chromedriver" CONST_WEBDRIVER_TYPE_UC = "undetected_chromedriver"
CONST_AUTO_RELOAD_RANDOM_DELAY_MAX_SECOND = 4 CONST_AUTO_RELOAD_RANDOM_DELAY_MAX_SECOND = 4
@ -510,7 +508,6 @@ def clean_uc_exe_cache():
return is_cache_exist return is_cache_exist
def load_chromdriver_uc(config_dict): def load_chromdriver_uc(config_dict):
import undetected_chromedriver as uc import undetected_chromedriver as uc
@ -648,22 +645,19 @@ def get_driver_by_config(config_dict):
# read config. # read config.
homepage = config_dict["homepage"] homepage = config_dict["homepage"]
browser = config_dict["browser"]
driver_type = config_dict["webdriver_type"]
# output config: # output config:
print("maxbot app version:", CONST_APP_VERSION) print("maxbot app version:", CONST_APP_VERSION)
print("python version:", platform.python_version()) print("python version:", platform.python_version())
print("platform:", platform.platform()) print("platform:", platform.platform())
print("homepage:", homepage) print("homepage:", homepage)
print("browser:", browser) print("browser:", config_dict["browser"])
print("ticket_number:", str(config_dict["ticket_number"])) print("ticket_number:", str(config_dict["ticket_number"]))
print(config_dict["tixcraft"]) print(config_dict["tixcraft"])
print("==[advanced config]==") print("==[advanced config]==")
print(config_dict["advanced"]) print(config_dict["advanced"])
print("webdriver_type:", driver_type) print("webdriver_type:", config_dict["webdriver_type"])
# entry point # entry point
if homepage is None: if homepage is None:
@ -675,10 +669,10 @@ def get_driver_by_config(config_dict):
webdriver_path = os.path.join(Root_Dir, "webdriver") webdriver_path = os.path.join(Root_Dir, "webdriver")
print("platform.system().lower():", platform.system().lower()) print("platform.system().lower():", platform.system().lower())
if browser in ["chrome","brave"]: if config_dict["browser"] in ["chrome","brave"]:
# method 6: Selenium Stealth # method 6: Selenium Stealth
if driver_type != CONST_WEBDRIVER_TYPE_UC: if config_dict["webdriver_type"] != CONST_WEBDRIVER_TYPE_UC:
driver = load_chromdriver_normal(config_dict, driver_type) driver = load_chromdriver_normal(config_dict, config_dict["webdriver_type"])
else: else:
# method 5: uc # method 5: uc
# multiprocessing not work bug. # multiprocessing not work bug.
@ -688,7 +682,7 @@ def get_driver_by_config(config_dict):
freeze_support() freeze_support()
driver = load_chromdriver_uc(config_dict) driver = load_chromdriver_uc(config_dict)
if browser == "firefox": if config_dict["browser"] == "firefox":
# default os is linux/mac # default os is linux/mac
# download url: https://github.com/mozilla/geckodriver/releases # download url: https://github.com/mozilla/geckodriver/releases
chromedriver_path = os.path.join(webdriver_path,"geckodriver") chromedriver_path = os.path.join(webdriver_path,"geckodriver")
@ -727,7 +721,7 @@ def get_driver_by_config(config_dict):
else: else:
print(exc) print(exc)
if browser == "edge": if config_dict["browser"] == "edge":
# default os is linux/mac # default os is linux/mac
# download url: https://developer.microsoft.com/zh-tw/microsoft-edge/tools/webdriver/ # download url: https://developer.microsoft.com/zh-tw/microsoft-edge/tools/webdriver/
chromedriver_path = os.path.join(webdriver_path,"msedgedriver") chromedriver_path = os.path.join(webdriver_path,"msedgedriver")
@ -748,7 +742,7 @@ def get_driver_by_config(config_dict):
left_part = error_message.split("Stacktrace:")[0] left_part = error_message.split("Stacktrace:")[0]
print(left_part) print(left_part)
if browser == "safari": if config_dict["browser"] == "safari":
driver = None driver = None
try: try:
driver = webdriver.Safari() driver = webdriver.Safari()
@ -11079,20 +11073,11 @@ def main(args):
while True: while True:
time.sleep(0.05) time.sleep(0.05)
is_alert_popup = False
# pass if driver not loaded. # pass if driver not loaded.
if driver is None: if driver is None:
print("web driver not accessible!") print("web driver not accessible!")
break break
#is_alert_popup = check_pop_alert(driver)
#MUST "do nothing: if alert popup.
#print("is_alert_popup:", is_alert_popup)
if is_alert_popup:
continue
url, is_quit_bot = get_current_url(driver) url, is_quit_bot = get_current_url(driver)
if is_quit_bot: if is_quit_bot:
break break
@ -11103,9 +11088,6 @@ def main(args):
if len(url) == 0: if len(url) == 0:
continue continue
# 說明:輸出目前網址,覺得吵的話,請註解掉這行。
#print("url:", url)
if len(url) > 0 : if len(url) > 0 :
if url != last_url: if url != last_url:
print(url) print(url)
@ -11179,7 +11161,7 @@ def main(args):
def cli(): def cli():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="resize image to new width") description="MaxBot Aggument Parser")
parser.add_argument("--input", parser.add_argument("--input",
help="config file path", help="config file path",
@ -11217,22 +11199,14 @@ def cli():
parser.add_argument("--browser", parser.add_argument("--browser",
help="overwrite browser setting", help="overwrite browser setting",
default='', default='',
choices=['chrome','firefox','edge','safari'], choices=['chrome','firefox','edge','safari','brave'],
type=str) type=str)
args = parser.parse_args() args = parser.parse_args()
main(args) main(args)
if __name__ == "__main__": def test_captcha_model():
CONST_MODE_GUI = 0 #for test kktix answer.
CONST_MODE_CLI = 1
mode = CONST_MODE_GUI
#mode = CONST_MODE_CLI
if mode == CONST_MODE_GUI:
cli()
else:
#for test kktix infer answer.
captcha_text_div_text = u"請回答下列問題,請在下方空格輸入DELIGHT請以半形輸入法作答大小寫需要一模一樣" captcha_text_div_text = u"請回答下列問題,請在下方空格輸入DELIGHT請以半形輸入法作答大小寫需要一模一樣"
#captcha_text_div_text = u"請在下方空白處輸入引號內文字「abc」" #captcha_text_div_text = u"請在下方空白處輸入引號內文字「abc」"
#captcha_text_div_text = u"請在下方空白處輸入引號內文字「0118eveconcert」請以半形小寫作答。" #captcha_text_div_text = u"請在下方空白處輸入引號內文字「0118eveconcert」請以半形小寫作答。"
@ -11265,3 +11239,13 @@ if __name__ == "__main__":
image_bytes = f.read() image_bytes = f.read()
res = ocr.classification(image_bytes) res = ocr.classification(image_bytes)
print(res) print(res)
if __name__ == "__main__":
debug_captcha_model_flag = False # online mode
# for debug purpose.
#debug_captcha_model_flag = True
if not debug_captcha_model_flag:
cli()
else:
test_captcha_model()