如何在不显示浏览器的情况下运行 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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句