当前位置:   article > 正文

selenium启动参数设置

selenium启动参数设置

1. selenium

selenium启动配置参数接收是ChromeOptions类,创建方式如下:

from selenium import webdriver
option = webdriver.ChromeOptions()
  • 1
  • 2
class SELEDEMO:
    def __init__(self):
	    #启动配置参数接收是ChromeOptions类,创建方式如下:
        options = webdriver.ChromeOptions()
        prefs = {
            'profile.default_content_setting_values': {
                'images': 2,  # 无图
                'javascript': 2,  # 禁止脚本加载
                'permissions.default.stylesheet': 2,  # 禁用css
            }}
        options.add_experimental_option('prefs', prefs)
        # 禁用插件
        options.add_argument('--disable-plugins')
        # 禁用显卡
        options.add_argument('--disable--gpu')
        # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
        options.add_argument("--headless")
        # 添加UA
        options.add_argument(
            "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
            "Chrome/95.0.4638.69 Safari/537.36")
        # 指定引擎,可以加快启动时间
        self.driver = webdriver.Chrome(service=Service('E:\document\chromedriver-win64\chromedriver.exe'), options=options)
        # 刷新页面
        self.driver.refresh()
        self.wait = WebDriverWait(self.driver, 10)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

chromedriver.exe下载地址:
下载地址:https://chromedriver.chromium.org/downloads

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/523967
推荐阅读
相关标签
  

闽ICP备14008679号