Using chrome headless option in selenium

After my wife inadvertently interrupted my long scraping session while switching on Netflix for my daughter, I decided that I needed something a bit more robust, and found that Chrome had a headless option that Selenium could use:


from selenium import webdriver
from import Options
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")#; // open Browser in maximized mode
options.add_argument("disable-infobars")#; // disabling infobars
options.add_argument("--disable-extensions")#; // disabling extensions
options.add_argument("--disable-gpu")#; // applicable to windows os only
options.add_argument("--disable-dev-shm-usage") # // overcome limited resource problems
options.add_argument("--no-sandbox") # Bypass OS security model
options.binary_location = "/opt/google/chrome/chrome"
driver = webdriver.Chrome(chrome_options=options)

Use the above options. Some of these are required to overcome the dreaded error:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)