zoukankan      html  css  js  c++  java
  • Python 封装 浏览器驱动 工具类

    # coding=utf-8
    
    from selenium import webdriver
    import os, sys
    
    from selenium.common.exceptions import WebDriverException
    
    driver_base = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    sys.path.append(driver_base)
    
    driver = None
    
    
    def init_driver(browser=None):
        global driver
        try:
            if browser is None or browser == 'Chrome':
                option = webdriver.ChromeOptions()
                # 增加Chrome启动时属性,去掉告警提示
                # option.add_argument("disable-infobars")
                # 开启无痕模式
                option.add_argument('--incognito')
                path = os.path.join(driver_base, 'config\chromedriver.exe')
                driver = webdriver.Chrome(executable_path=path, options=option)
            elif browser == 'Firefox':
                path = os.path.join(driver_base, 'config\geckodriver.exe')
                driver = webdriver.Firefox(executable_path=path)
            return driver
        except WebDriverException as e:
            raise e
    不积跬步,无以至千里;不积小流,无以成江海。
  • 相关阅读:
    常用FPGA功能块记录
    鸿蒙相关
    微波相关
    Python库大全
    C#环境实现代码的自动生成编译
    STM32相关
    硬件相关
    C# 获取枚举中文注释
    C# 获取自定义特性值
    Asp.Net Core 中 Host 与 WebHost的区别
  • 原文地址:https://www.cnblogs.com/xuezhimin-esage-2020/p/14512418.html
Copyright © 2011-2022 走看看