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:通过自动拒绝来抑制所有权限提示。
相关推荐
金銀銅鐵5 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup1110 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi0012 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵14 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf15 小时前
Agent 流程编排
后端·python·agent
copyer_xyf15 小时前
Agent RAG
后端·python·agent
copyer_xyf15 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf15 小时前
Agent 记忆管理
后端·python·agent
星云穿梭1 天前
用Python写一个带图形界面的学生管理系统——完整教程
python