Creating a headless Chrome instance in Python Creating a headless Chrome instance in Python google-chrome google-chrome

Creating a headless Chrome instance in Python


This question is 5 years old now and at the time it was a big challenge to run a headless chrome using python, but the good news is:

Starting from version 59, released in June 2017, Chrome comes with a headless driver, meaning we can use it in a non-graphical server environment and run tests without having pages visually rendered etc which saves a lot of time and memory for testing or scraping. Setting Selenium for that is very easy:

(I assume that you have installed selenium and chrome driver):

from selenium import webdriver#set a headless browseroptions = webdriver.ChromeOptions()options.add_argument('headless')browser = webdriver.Chrome(chrome_options=options)

and now your chrome will run headlessly, if you take out options from the last line, it will show you the browser.


While I'm the author of CasperJS, I invite you to check out Ghost.py, a webkit web client written in Python.

While it's heavily inspired by CasperJS, it's not based on PhantomJS — it still uses PyQt bindings and Webkit though.