Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium: How to use Headless Chrome on AWS?

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.

like image 937
Volatil3 Avatar asked Jan 31 '18 07:01

Volatil3


2 Answers

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!

like image 141
Leon Avatar answered Nov 13 '22 06:11

Leon


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()
like image 4
Peter Avatar answered Nov 13 '22 06:11

Peter