Python, selenium - 我如何 运行 脚本而不显示浏览器 window

Python, selenium - How can I run the script without showing the browser window

如何在不显示浏览器的情况下运行 selenium 代码(代码运行 但浏览器window 不会显示)?

您可以使用无头模式,运行Selenium 脚本不显示浏览器。

到 运行 chrome-headless 只需通过 chrome_options.add_argument 添加 --headless ,如下所示:

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)