在 Python 中运行 selenium 时,有没有办法隐藏浏览器?

Abh*_*lvi 2 python selenium python-3.x selenium-webdriver

我正在使用 selenium 进行一个项目来抓取数据,但我不希望浏览器打开并弹出。我只是想隐藏浏览器,也不想在任务栏中显示它......

有些人还建议使用 phantomJS 但我没有得到它们。现在做什么 ...

小智 7

如果您使用的是 Chrome,您可以像这样设置 headless 参数:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

driver_exe = 'chromedriver'
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(driver_exe, options=options)
Run Code Online (Sandbox Code Playgroud)