Python - Firefox Headless

后端 未结 5 593
孤独总比滥情好
孤独总比滥情好 2020-12-05 05:38

I\'ve spent the last few days messing around with Selenium, Tor, and Firefox as a combination for multiple tasks. I\'ve managed to write a simple script in Python that takes

5条回答
  •  遥遥无期
    2020-12-05 06:11

    Since version 56 release at September 28, 2017, Firefox headless mode is available in all three main operating system.

    You can set headless mode through webdriver.FirefoxOptions(), just like you did with Chrome:

    from selenium import webdriver
    
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    driver = webdriver.Firefox(options=options)
    

    P.S. If you use Selenium < 3.8.0, you have to replace webdriver.FirefoxOptions() with webdriver.firefox.options.Options() (see PR #5120).

    Besides, use enviroment variable MOZ_HEADLESS will do the same thing:

    import os
    from selenium import webdriver
    
    os.environ['MOZ_HEADLESS'] = '1'  # <- this line
    driver = webdriver.Firefox()
    

提交回复
热议问题