ver 2022-07-27, fix for urbtix.
parent
8e72932db4
commit
3e117c2a9e
|
@ -7,7 +7,8 @@ import json
|
||||||
import random
|
import random
|
||||||
#print("python version", platform.python_version())
|
#print("python version", platform.python_version())
|
||||||
|
|
||||||
from selenium import webdriver
|
#from selenium import webdriver
|
||||||
|
from seleniumwire import webdriver
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support.ui import Select
|
from selenium.webdriver.support.ui import Select
|
||||||
|
|
||||||
|
@ -20,6 +21,8 @@ from selenium.common.exceptions import NoAlertPresentException
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.common.exceptions import TimeoutException
|
from selenium.common.exceptions import TimeoutException
|
||||||
|
# for chrome 103
|
||||||
|
from selenium.common.exceptions import WebDriverException
|
||||||
|
|
||||||
# for ["pageLoadStrategy"] = "eager"
|
# for ["pageLoadStrategy"] = "eager"
|
||||||
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
|
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
|
||||||
|
@ -51,7 +54,7 @@ ssl._create_default_https_context = ssl._create_unverified_context
|
||||||
#附註1:沒有寫的很好,很多地方應該可以模組化。
|
#附註1:沒有寫的很好,很多地方應該可以模組化。
|
||||||
#附註2:
|
#附註2:
|
||||||
|
|
||||||
CONST_APP_VERSION = u"MaxBot (2022.06.24)"
|
CONST_APP_VERSION = u"MaxBot (2022.07.27)"
|
||||||
|
|
||||||
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"
|
||||||
|
@ -293,14 +296,11 @@ def load_config_from_local(driver):
|
||||||
if len(homepage) == 0:
|
if len(homepage) == 0:
|
||||||
homepage = "https://tixcraft.com/activity/"
|
homepage = "https://tixcraft.com/activity/"
|
||||||
|
|
||||||
|
#driver_type = 'stealth'
|
||||||
|
driver_type = 'undetected_chromedriver'
|
||||||
|
|
||||||
Root_Dir = ""
|
Root_Dir = ""
|
||||||
if browser == "chrome":
|
if browser == "chrome":
|
||||||
# method 5: uc
|
|
||||||
#import undetected_chromedriver as uc
|
|
||||||
|
|
||||||
# method 6: Selenium Stealth
|
|
||||||
from selenium_stealth import stealth
|
|
||||||
|
|
||||||
DEFAULT_ARGS = [
|
DEFAULT_ARGS = [
|
||||||
'--disable-audio-output',
|
'--disable-audio-output',
|
||||||
'--disable-background-networking',
|
'--disable-background-networking',
|
||||||
|
@ -352,6 +352,20 @@ def load_config_from_local(driver):
|
||||||
#'--incognito',
|
#'--incognito',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# default os is linux/mac
|
||||||
|
chromedriver_path =Root_Dir+ "webdriver/chromedriver"
|
||||||
|
if platform.system()=="windows":
|
||||||
|
chromedriver_path =Root_Dir+ "webdriver/chromedriver.exe"
|
||||||
|
|
||||||
|
# method 5: uc
|
||||||
|
if driver_type=="undetected_chromedriver":
|
||||||
|
#import undetected_chromedriver as uc
|
||||||
|
import seleniumwire.undetected_chromedriver as uc
|
||||||
|
|
||||||
|
# method 6: Selenium Stealth
|
||||||
|
if driver_type=="stealth":
|
||||||
|
from selenium_stealth import stealth
|
||||||
|
|
||||||
chrome_options = webdriver.ChromeOptions()
|
chrome_options = webdriver.ChromeOptions()
|
||||||
|
|
||||||
# for navigator.webdriver
|
# for navigator.webdriver
|
||||||
|
@ -363,11 +377,6 @@ def load_config_from_local(driver):
|
||||||
#chrome_options.add_argument('blink-settings=imagesEnabled=false')
|
#chrome_options.add_argument('blink-settings=imagesEnabled=false')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# default os is linux/mac
|
|
||||||
chromedriver_path =Root_Dir+ "webdriver/chromedriver"
|
|
||||||
if platform.system()=="windows":
|
|
||||||
chromedriver_path =Root_Dir+ "webdriver/chromedriver.exe"
|
|
||||||
|
|
||||||
#caps = DesiredCapabilities().CHROME
|
#caps = DesiredCapabilities().CHROME
|
||||||
caps = chrome_options.to_capabilities()
|
caps = chrome_options.to_capabilities()
|
||||||
|
|
||||||
|
@ -379,6 +388,22 @@ def load_config_from_local(driver):
|
||||||
caps["unhandledPromptBehavior"] = u"ignore"
|
caps["unhandledPromptBehavior"] = u"ignore"
|
||||||
#caps["unhandledPromptBehavior"] = u"dismiss"
|
#caps["unhandledPromptBehavior"] = u"dismiss"
|
||||||
|
|
||||||
|
chrome_service = Service(chromedriver_path)
|
||||||
|
|
||||||
|
# method 6: Selenium Stealth
|
||||||
|
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
|
||||||
|
|
||||||
|
# Selenium Stealth settings
|
||||||
|
stealth(driver,
|
||||||
|
languages=["zh-TW", "zh"],
|
||||||
|
vendor="Google Inc.",
|
||||||
|
platform="Win32",
|
||||||
|
webgl_vendor="Intel Inc.",
|
||||||
|
renderer="Intel Iris OpenGL Engine",
|
||||||
|
fix_hairline=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#print("caps:", caps)
|
#print("caps:", caps)
|
||||||
|
|
||||||
# method 1:
|
# method 1:
|
||||||
|
@ -393,35 +418,33 @@ def load_config_from_local(driver):
|
||||||
#driver = webdriver.Chrome(desired_capabilities=caps, executable_path=chromedriver_path)
|
#driver = webdriver.Chrome(desired_capabilities=caps, executable_path=chromedriver_path)
|
||||||
|
|
||||||
# method 4:
|
# method 4:
|
||||||
chrome_service = Service(chromedriver_path)
|
#chrome_service = Service(chromedriver_path)
|
||||||
#driver = webdriver.Chrome(options=chrome_options, service=chrome_service)
|
#driver = webdriver.Chrome(options=chrome_options, service=chrome_service)
|
||||||
|
|
||||||
|
|
||||||
# method 5: uc
|
# method 5: uc
|
||||||
'''
|
#options = webdriver.ChromeOptions()
|
||||||
|
if driver_type=="undetected_chromedriver":
|
||||||
options = uc.ChromeOptions()
|
options = uc.ChromeOptions()
|
||||||
options.add_argument("--no-first-run --no-service-autorun --password-store=basic")
|
options.add_argument("--password-store=basic")
|
||||||
options.page_load_strategy="eager"
|
options.page_load_strategy="eager"
|
||||||
#print("strategy", options.page_load_strategy)
|
#print("strategy", options.page_load_strategy)
|
||||||
|
|
||||||
if os.path.exists(chromedriver_path):
|
if os.path.exists(chromedriver_path):
|
||||||
print("Use user driver path:", chromedriver_path)
|
print("Use user driver path:", chromedriver_path)
|
||||||
driver = uc.Chrome(service=chrome_service, options=options, suppress_welcome=False)
|
#driver = uc.Chrome(service=chrome_service, options=options, suppress_welcome=False)
|
||||||
|
driver = uc.Chrome(executable_path=chromedriver_path, options=options)
|
||||||
else:
|
else:
|
||||||
print("Not assign driver path...")
|
print("Oops! web driver not on path...")
|
||||||
driver = uc.Chrome(options=options, suppress_welcome=False)
|
driver = uc.Chrome(options=options, suppress_welcome=False)
|
||||||
'''
|
|
||||||
|
|
||||||
# method 6: Selenium Stealth
|
download_dir_path="."
|
||||||
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
|
params = {
|
||||||
|
"behavior": "allow",
|
||||||
|
"downloadPath": os.path.realpath(download_dir_path)
|
||||||
|
}
|
||||||
|
driver.execute_cdp_cmd("Page.setDownloadBehavior", params)
|
||||||
|
|
||||||
# Selenium Stealth settings
|
|
||||||
stealth(driver,
|
|
||||||
languages=["zh-TW", "zh"],
|
|
||||||
vendor="Google Inc.",
|
|
||||||
platform="Win32",
|
|
||||||
webgl_vendor="Intel Inc.",
|
|
||||||
renderer="Intel Iris OpenGL Engine",
|
|
||||||
fix_hairline=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
if browser == "firefox":
|
if browser == "firefox":
|
||||||
# default os is linux/mac
|
# default os is linux/mac
|
||||||
|
@ -443,8 +466,12 @@ def load_config_from_local(driver):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
print("goto url:", homepage)
|
||||||
driver.get(homepage)
|
driver.get(homepage)
|
||||||
|
except WebDriverException:
|
||||||
|
print('oh no not again !')
|
||||||
except Exception as exec1:
|
except Exception as exec1:
|
||||||
|
print('get() raise Exception:', exec1)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -2714,8 +2741,10 @@ def urbtix_ticket_number_auto_select(driver, url, ticket_number):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print("find ticket_number select fail")
|
print("find ticket_number select fail...")
|
||||||
print(exc)
|
time.sleep(0.1)
|
||||||
|
#print(exc)
|
||||||
|
pass
|
||||||
|
|
||||||
return ret, is_assign_ticket_number
|
return ret, is_assign_ticket_number
|
||||||
|
|
||||||
|
@ -2812,13 +2841,15 @@ def urbtix_area_auto_select(driver, url, kktix_area_keyword):
|
||||||
def urbtix_next_button_press(driver, url):
|
def urbtix_next_button_press(driver, url):
|
||||||
ret = False
|
ret = False
|
||||||
try:
|
try:
|
||||||
el = driver.find_element(By.CSS_SELECTOR, '#express-purchase-btn > div > span')
|
el = driver.find_element(By.CSS_SELECTOR, '#free-seat-purchase-btn')
|
||||||
if el is not None:
|
if el is not None:
|
||||||
ret = True
|
el_span = el.find_element(By.TAG_NAME, 'span')
|
||||||
|
if el_span is not None:
|
||||||
|
#ret = True
|
||||||
#print("bingo, found next button")
|
#print("bingo, found next button")
|
||||||
|
|
||||||
if el.is_enabled():
|
if el_span.is_enabled():
|
||||||
el.click()
|
el_span.click()
|
||||||
ret = True
|
ret = True
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print("find next button fail")
|
print("find next button fail")
|
||||||
|
|
|
@ -3,3 +3,5 @@ chardet
|
||||||
idna
|
idna
|
||||||
selenium
|
selenium
|
||||||
selenium-stealth
|
selenium-stealth
|
||||||
|
selenium-wire
|
||||||
|
undetected-chromedriver
|
||||||
|
|
|
@ -17,7 +17,7 @@ import sys
|
||||||
import platform
|
import platform
|
||||||
import json
|
import json
|
||||||
|
|
||||||
CONST_APP_VERSION = u"MaxBot (2022.06.24)"
|
CONST_APP_VERSION = u"MaxBot (2022.07.27)"
|
||||||
|
|
||||||
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"
|
||||||
|
|
Loading…
Reference in New Issue