【selenium】下载并配置chromedriver
1、下载地址
https://registry.npmmirror.com/binary.html?path=chromedriver/
2、工程配置
3、使用
class BaseAction(object): def __init__(self, mode=0): """ :param mode: 0: 表示无头模式, 1:表示GUI模式 """ self.mode = mode self.options = webdriver.ChromeOptions() serv = Service(executable_path=r"{}".format(self.get_driver_path_by_sys())) if self.mode == 0: self.options.add_argument('--headless') self.options.add_argument('--disable-gpu') if self.sys_type == 'Windows': self.browser = webdriver.Chrome(service=serv, options=self.options) else: self.browser = webdriver.Chrome(executable_path=self.get_driver_path_by_sys(), options=self.options) else: if self.sys_type == 'Windows': self.browser = webdriver.Chrome(service=serv) else: self.browser = webdriver.Chrome(executable_path=self.get_driver_path_by_sys()) self.login_vpn() def get_driver_path_by_sys(self): self.sys_type = platform.system() if self.sys_type == "Windows": debug_logger.info("system type: Windows") return os.path.join(G.VAR_PROJECT_ROOT_PATH, 'third_party', 'chromedriver', 'chromedriver_win32', 'chromedriver.exe') elif self.sys_type == "Linux": debug_logger.info("system type: Linux") return os.path.join(G.VAR_PROJECT_ROOT_PATH, 'third_party', 'chromedriver', 'chromedriver_linux64', 'chromedriver') else: raise Exception("system not support!")