Selenium: How to use Headless Chrome on AWS?

旧时模样 提交于 2020-05-24 20:33:10

问题


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.


回答1:


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!




回答2:


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()


来源:https://stackoverflow.com/questions/48537028/selenium-how-to-use-headless-chrome-on-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!