1. 程式人生 > >把chrome設定成無頭瀏覽器,配合selenium使用

把chrome設定成無頭瀏覽器,配合selenium使用

正常情況下的呼叫是:

from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver

driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
# driver.get('https://www.baidu.com')

當除錯好後,需要設定成無頭的chrome:

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
wait = WebDriverWait(driver, 20)
# driver.get('https://www.baidu.com')