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:通过自动拒绝来抑制所有权限提示。
相关推荐
珺毅同学8 小时前
YOLO生成预测json标签迁移问题
python·yolo·json
骑士雄师8 小时前
18.4 长期记忆可修改版
python
~小先生~8 小时前
Python从入门到放弃(一)
开发语言·python
天佑木枫8 小时前
第2天:变量与数据类型 —— 让程序记住信息
python
Dust-Chasing9 小时前
Claude Code源码剖析 - Claude Code 上下文压缩机制
人工智能·python·ai
Cloud_Shy61810 小时前
解读《Effective Python 3rd Edition》:从练气到老魔(第五章 Item 33 - 35)
开发语言·人工智能·笔记·python·学习方法
abcy07121311 小时前
python pandas csv异步后台清洗前端优先返回成功信息
前端·python·pandas
颜酱11 小时前
LangChain使用RAG 入门:让大模型读懂你的私有文档
python·langchain
天天进步201512 小时前
Python全栈项目--校园智能宿舍管理系统
开发语言·python
测试员周周12 小时前
【AI测试智能体-面试】AI测试面试60题(附回答思路)
人工智能·python·功能测试·测试工具·单元测试·自动化·测试用例