Selenium: How to use Headless Chrome on AWS?

前端 未结 2 1300
盖世英雄少女心
盖世英雄少女心 2021-02-02 00:35

Today I saw the message UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead.

I am wil

相关标签:
2条回答
  • 2021-02-02 01:08

    I prefer to use Firefox so this is my Python3 implementation

    def createHeadlessFirefoxBrowser():
         options = webdriver.FirefoxOptions()
         options.add_argument('--headless')
         return webdriver.Firefox(options=options)
    
    browser = createHeadlessFirefoxBrowser()
    
    0 讨论(0)
  • 2021-02-02 01:16

    Create a new EC2 instance.

    SSH log into the machine.

    Install python, selenium, chromedriver, chromium, and python packages what you need.

    sudo apt install chromium-chromedriver
    

    Copy your python script to the machine.

    Edit the script and add an chromeoption.

    import selenium as se
    
    options = se.webdriver.ChromeOptions()
    options.add_argument('headless')
    
    driver = se.webdriver.Chrome(chrome_options=options)
    

    Done!

    0 讨论(0)
提交回复
热议问题