selenium中webdriver常用的ChromeOptions参数

官网链接:Browser Options | Selenium

使用示例:

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

# 创建选项对象
options = Options()

# 设置浏览器启动时的窗口大小
options.add_argument("--window-size=1920,1080")

# 启动浏览器时不显示图形界面
options.add_argument("--headless")

# 创建Chrome WebDriver时传入选项对象
driver = webdriver.Chrome(options=options)

# 访问网页
driver.get("https://www.example.com")

# 在这里进行其他操作...

# 关闭浏览器
driver.quit()

常用参数:

  1. add_argument(argument):添加命令行参数。
  2. add_experimental_option(name, value):添加实验性质的选项。
  3. binary_location:设置Chrome浏览器可执行文件的路径。
  4. debugger_address:指定远程调试地址。
  5. headless:设置浏览器是否以无头模式(不显示界面)运行。
  6. window_size:设置浏览器窗口的大小。
  7. user_data_dir:指定用户数据目录,可以用于设置用户配置、缓存等信息。
  8. profile_directory:指定用户配置文件目录。
  9. disable_extensions:禁用扩展程序。
  10. disable_gpu:禁用GPU加速。
  11. no_sandbox:禁用沙盒模式。
  12. disable_notifications:禁用通知。
  13. disable_infobars:禁用信息栏。
  14. disable_web_security:禁用Web安全性。
  15. incognito:启动隐身模式。
  16. ignore_certificate_errors:忽略SSL证书错误。
  17. disable_dev_shm_usage:禁用/dev/shm使用。
  18. disable_setuid_sandbox:禁用setuid沙盒。
  19. disable_background_networking:禁用后台网络。
  20. disable_client_side_phishing_detection:禁用客户端端钓鱼检测。
  21. disable_component_extensions_with_background_pages:禁用后台页面的组件扩展例如密码管理、自动填表、翻译等。
  22. disable_default_apps:禁用默认应用。
  23. disable_file_system:禁用文件系统API。
  24. disable_fullscreen:禁用全屏模式。
  25. disable_sync:禁用同步功能。
  26. disable_tab_for_desktop_share:禁用桌面共享选项卡。
  27. disable-features=Translate:禁用 Chrome 翻译,包括手动选项和检测到不同语言的页面时弹出的提示。
  28. disable-features=GlobalMediaControls:隐藏可打开用于控制媒体会话的对话框的工具栏按钮。
  29. disable-external-intent-requests:禁止在外部应用程序中打开链接。
  30. disable-notifications:禁用 Web 通知和推送 API
  31. disable-sync:禁用同步到 Google 帐户
  32. hide_scrollbars:隐藏滚动条。
  33. mute_audio:静音浏览器。
  34. no-first-run:跳过首次运行向导
  35. aggressive-cache-discard:缓存丢弃
  36. allow-running-insecure-content:允许运行不安全内容
  37. deny-permission-prompts:通过自动拒绝来抑制所有权限提示。
相关推荐
9527(●—●)3 分钟前
windows系统python开发pip命令使用(菜鸟学习)
开发语言·windows·python·学习·pip
森叶21 分钟前
手搓一个 Windows 注册表清理器:从开发到 EXE 打包全流程
windows·python
骚戴39 分钟前
大语言模型(LLM)进阶:从闭源大模型 API 到开源大模型本地部署,四种接入路径全解析
java·人工智能·python·语言模型·自然语言处理·llm·开源大模型
柒壹漆41 分钟前
用Python制作一个USB Hid设备数据收发测试工具
开发语言·git·python
东哥很忙XH1 小时前
python使用PyQt5开发桌面端串口通信
开发语言·驱动开发·python·qt
Dxy12393102161 小时前
Python的正则表达式入门:从小白到能手
服务器·python·正则表达式
艾上编程1 小时前
第三章——爬虫工具场景之Python爬虫实战:行业资讯爬取与存储,抢占信息先机
开发语言·爬虫·python
Pyeako1 小时前
网络爬虫相关操作--selenium库(超详细版)
爬虫·python·selenium
dagouaofei1 小时前
全面整理6款文档生成PPT工具,PDF转PPT不再难
python·pdf·powerpoint
β添砖java1 小时前
python第一阶段第10章
开发语言·python