【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!")
复制代码

 

posted @   代码诠释的世界  阅读(443)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2019-03-15 Python实现8中常用排序算法
2019-03-15 Java基础之 HelloWorld
点击右上角即可分享
微信分享提示