【selenium】下载并配置chromedriver
1、下载地址
https://registry.npmmirror.com/binary.html?path=chromedriver/
http://chromedriver.storage.googleapis.com/index.html
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!")
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2019-03-15 Python实现8中常用排序算法
2019-03-15 Java基础之 HelloWorld