赞
踩
selenium启动配置参数接收是ChromeOptions类,创建方式如下:
from selenium import webdriver
option = webdriver.ChromeOptions()
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)
chromedriver.exe下载地址:
下载地址:https://chromedriver.chromium.org/downloads
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。