Running Selenium with Headless Chrome Webdriver

To run chrome-headless just add --headless via chrome_options.add_argument, i.e.:

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.headless = True # also works
driver = webdriver.Chrome(options=chrome_options)
start_url = "https://duckgo.com"
driver.get(start_url)
print(driver.page_source.encode("utf-8"))
driver.quit()
# b'<!DOCTYPE html><html xmlns="http://www....

So my thought is that running it with headless chrome would make my script faster.

Try using chrome options like --disable-extensions or --disable-gpu and benchmark it, but I wouldn’t count with much improvement.


References: headless-chrome

Note: As of today, when running chrome headless on Windows., you should include the  --disable-gpu flag See crbug.com/737678

Leave a Comment