selenium 选项 chrome_options

当前环境:

Windows 10 + Python 3.7 + selenium 3.141.0 + Google Chrome 115.0.5790.110 (64 位)

一种方法:

python 复制代码
from selenium import webdriver


if __name__ == '__main__':
    # chrome 选项配置
    chrome_options = webdriver.ChromeOptions()
    # 设置无界面浏览
    # chrome_options.add_argument('--headless')
    # 忽略证书报错
    chrome_options.add_argument('ignore-certificate-errors')
    # 取消chrome受自动控制提示
    chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
    # 关掉密码弹窗
    prefs = {"": "", "credentials_enable_service": False, "profile.password_manager_enabled": False}
    chrome_options.add_experimental_option("prefs", prefs)
    # Chrome.exe 路径
    chrome_options.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
    # chromedriver.exe 路径
    ChromedriverPath = r'.\chromedriver.exe'
    driver = webdriver.Chrome(ChromedriverPath, options=chrome_options)

    # 打开百度
    driver.get('https://www.baidu.com')

另外一种方法:

python 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


if __name__ == '__main__':
    # chrome 选项配置
    options = Options()
    # 设置无界面浏览
    # options.add_argument('--headless')
    # 忽略证书报错
    options.add_argument('ignore-certificate-errors')
    # 取消chrome受自动控制提示
    options.add_experimental_option("excludeSwitches", ['enable-automation'])
    # 关掉密码弹窗
    prefs = {"": "", "credentials_enable_service": False, "profile.password_manager_enabled": False}
    options.add_experimental_option("prefs", prefs)
    # Chrome.exe 路径
    options.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
    # chromedriver.exe 路径
    ChromedriverPath = r'.\chromedriver.exe'
    driver = webdriver.Chrome(ChromedriverPath, options=options)

    # 打开百度
    driver.get('https://www.baidu.com')

参考:

selenium关闭左上方Chrome 正受到自动测试软件的控制的提示 - 简书

https://www.cnblogs.com/yangjintao/p/10599868.html

相关推荐
小白学大数据1 小时前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
周杰伦的稻香3 小时前
tcpdump
网络·测试工具·tcpdump
金玉满堂@bj3 小时前
什么是静态测试?
测试工具
chenjingming6664 小时前
jmeter导入浏览器上按F12抓的数据包
前端·chrome·jmeter
John_ToDebug6 小时前
Chrome 首次启动引导页里触发 Pref 设置,为什么主进程收不到 IPC
c++·chrome
小鹿软件办公6 小时前
谷歌 Chrome 终于推出垂直标签页与更智能的阅读模式
前端·chrome
杜子不疼.6 小时前
Python + Selenium + AI 智能爬虫:自动识别反爬与数据提取
人工智能·python·selenium
John_ToDebug6 小时前
Chromium 页面类型与 IPC 通信机制深度解析
前端·c++·chrome
淼淼爱喝水1 天前
Ansible 基础模块实战作业详细教程
chrome·github·ansible
williamdsy1 天前
专业的办公家具解决方案
测试工具