use stealth instead of undetected_chromedriver

master
CHUN YU YAO 2022-07-27 06:40:50 +08:00
parent 3e117c2a9e
commit c145d588ee
1 changed files with 12 additions and 8 deletions

View File

@ -7,8 +7,14 @@ import json
import random import random
#print("python version", platform.python_version()) #print("python version", platform.python_version())
#from selenium import webdriver driver_type = 'stealth'
from seleniumwire import webdriver #driver_type = 'undetected_chromedriver'
if driver_type=="undetected_chromedriver":
from seleniumwire import webdriver
else:
from selenium 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
@ -296,9 +302,6 @@ 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":
DEFAULT_ARGS = [ DEFAULT_ARGS = [
@ -354,7 +357,8 @@ def load_config_from_local(driver):
# default os is linux/mac # default os is linux/mac
chromedriver_path =Root_Dir+ "webdriver/chromedriver" chromedriver_path =Root_Dir+ "webdriver/chromedriver"
if platform.system()=="windows": print("platform.system().lower():", platform.system().lower())
if platform.system().lower()=="windows":
chromedriver_path =Root_Dir+ "webdriver/chromedriver.exe" chromedriver_path =Root_Dir+ "webdriver/chromedriver.exe"
# method 5: uc # method 5: uc
@ -435,7 +439,7 @@ def load_config_from_local(driver):
#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) driver = uc.Chrome(executable_path=chromedriver_path, options=options)
else: else:
print("Oops! web driver not on path...") print("Oops! web driver not on path:",chromedriver_path )
driver = uc.Chrome(options=options, suppress_welcome=False) driver = uc.Chrome(options=options, suppress_welcome=False)
download_dir_path="." download_dir_path="."
@ -449,7 +453,7 @@ def load_config_from_local(driver):
if browser == "firefox": if browser == "firefox":
# default os is linux/mac # default os is linux/mac
chromedriver_path =Root_Dir+ "webdriver/geckodriver" chromedriver_path =Root_Dir+ "webdriver/geckodriver"
if platform.system()=="windows": if platform.system().lower()=="windows":
chromedriver_path =Root_Dir+ "webdriver/geckodriver.exe" chromedriver_path =Root_Dir+ "webdriver/geckodriver.exe"
firefox_service = Service(chromedriver_path) firefox_service = Service(chromedriver_path)