selenium的无头模式--headless
from selenium.webdriver.firefox.options import Options
Options().add_argument('--headless')
或者:
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.add_argument('--headless')
browser = webdriver.Firefox(options=options)
或者: selenium+Headless Chrome实现不弹出浏览器,后台运行
### 增加两个参数即可,“--headless” “--disable-gpu”
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PIL import Image,ImageEnhance
path = 'C:/dd/chromedriver.exe' # chromedriver.exe 驱动的路径
#打开浏览器
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# 创建浏览器对象
driver = webdriver.Chrome(executable_path=path, chrome_options=chrome_options)