A headless browser is a web browser without a user interface. This is great if you want to start a web browser to do tasks, but you don’t want or need to see it.

You can use a GUI browser like Firefox or Chrome. Then set it to headless mode. In any case, the web driver needs to be installed.

Related course:

selenium

selenium firefox headless

The code below starts Firefox, but in headless mode. It can do anything Firefox can, but it wont be visible on the screen. The screenshot below outputs the html code of the web page, but that’s optional.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from selenium import webdriver

try:
fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.set_headless()
brower = webdriver.Firefox(firefox_options=fireFoxOptions)

brower.get('https://pythonbasics.org')
print(brower.page_source)
finally:
try:
brower.close()
except:
pass

selenium firefox headless

Download examples