python - Python,selenium - 如何在不显示浏览器窗口的情况下运行脚本
问题描述
如何在不显示浏览器的情况下运行 selenium 代码(代码运行但浏览器窗口不会显示)?
解决方案
您可以使用无头模式,它运行 Selenium 脚本而不显示浏览器。
要运行 chrome-headless,只需添加 --headless via chrome_options.add_argument
,如下所示:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
#chrome_options.add_argument("--disable-extensions")
#chrome_options.add_argument("--disable-gpu")
#chrome_options.add_argument("--no-sandbox") # linux only
chrome_options.add_argument("--headless")
chrome_options.add_argument("--start-maximized");
# chrome_options.headless = True # also works
driver = webdriver.Chrome(options=chrome_options)
推荐阅读
- android - UPI 付款在 razorpay Android 集成中不起作用
- javascript - Node.js - 服务器端命令提示符命令输入?
- asp.net-core-webapi - dotnet ef dbcontext 脚手架在 vs2019 中无法正常工作
- ruby - 使用 fastlane 时在任何源中都找不到 rake-12.3.3
- python - Python Plotly Sankey 图:链接通过节点而不是围绕它们
- java - 如何避免重新部署相同的工件?
- python - 如何防止crontab同时执行?
- java - Scala IntList 到 Java
- string - 如何找到包含给定字符串的双端 fastq 文件的百分比
- node.js - 使用 Node、Express、Handlebars 堆栈时,此错误的可能来源是什么?