How to set Selenium’s headless mode in python.

If you are thinking web scraping with Selenium, headless mode is good choice for you.

You can easily run a scraper file on crontab without settings on the server’s display in headless mode. It differs a lot if you use it or not.

To use the headless mode, you only set the following snippet in your scraper file.

from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True

download sourcecode

This syntax was introduced in 2018 and checked still working as of July 2021.

Happy web scraping!

Leave a Reply

Your email address will not be published. Required fields are marked *