15

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

I am willing to for for Chrome route. How do I install on AWS and run it on my remote AWS instance?

I will be using selenium in Python.

Volatil3
  • 14,253
  • 38
  • 134
  • 263

2 Answers2

15

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!

Leon
  • 634
  • 1
  • 7
  • 22
  • I see this when I do that: `selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.` – Ed Summers Sep 21 '18 at 20:19
  • 1
    @EdSummers Find chromedriver executable path and add the path into your PATH environment variable. – Leon Nov 28 '18 at 06:11
  • @Leon how to do that? – greendino Apr 22 '22 at 02:40
  • Here is a good article about path: [How to set your $PATH variable in Linux](https://opensource.com/article/17/6/set-path-linux) – Leon Apr 23 '22 at 06:05
4

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()
Peter
  • 202
  • 2
  • 5