pythonpython-3.xseleniumselenium-webdriver

Is there a way to hide the browser while running selenium in Python?


I am working on a project with selenium to scrape the data, but I don't want the browser to open and pop up. I just wanted to hide the browser and also not to display it in the taskbar also...

Some also suggested to use phantomJS but I didn't get them. What to do now ...


Solution

  • If you're using Chrome you can just set the headless argument like so:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    driver_exe = 'chromedriver'
    options = Options()
    options.add_argument("--headless")
    driver = webdriver.Chrome(driver_exe, options=options)