[PYTHON] Build a Selenium environment on Amazon Linux 2 in the shortest time

This article is the Amazon Linux 2 version of Building a Selenium Environment on Amazon Linux in the Shortest Time. If you want to build a Selenium environment on Amazon Linux, please refer to the above link.

Overview

With the end of security updates for Amazon Linux on June 30, 2020, You can now build a Selenium environment on Amazon Linux 2. The procedure is almost the same, but there are some changes. The following is all done as root.

procedure

・ Install ** Google Chrome ** -Installation of ** GConf2 ** * Changed -Install ** ChromeDriver ** ・ Install ** Google Noto Fonts ** -Installation of ** Selenium ** * Changed

Install Google Chrome

If you do it with yum install google-chrome-stable, you will die from the dependency. Let's do the following:

curl https://intoli.com/install-google-chrome.sh | bash

The latest Google Chrome should work fine.

Install GConf2

In the case of Amazon Linux, I could not install it without adding the repository, It's easy to install on Amazon Linux 2.

yum -y install GConf2

Install Chrome Driver

Since the currently installed Google Chrome is 79.0.3945.88, get the corresponding 79.0.3945.36. You can check the version of Google Chrome with google-chrome-stable -version.

wget https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver /usr/local/bin/

Install Google Noto Fonts

At this rate, when I took a screenshot of the screen with Selenium Since Japanese characters are garbled, install the font. https://www.google.com/get/noto/

cd ~/Downloads   #Somewhere suitable
wget https://noto-website-2.storage.googleapis.com/pkgs/Noto-hinted.zip
unzip Noto-hinted.zip
mkdir -p /usr/share/fonts/opentype/noto
cp *otf *ttf /usr/share/fonts/opentype/noto
fc-cache -f -v # optional

Install Selenium

This is where Amazon Linux 2 became a hassle. In Amazon Linux2, pip is not included by default, so let's install pip first. The default python version of Amazon Linux 2 is 2.7.16, so I really want to upgrade to 3 series before installing pip, Since there was a concern that yum would not work, I installed it as it is.

yum install -y python-pip

After that, you can install selenium.

pip install selenium

That's all there is to install.

Let's use Selenium

Create a simple test code to take a screenshot of the google top page Let's run it.

test.py


from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--window-size=1280,1024')
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://www.google.co.jp/')
driver.save_screenshot('test.png')

Test.png is created in the execution directory.

By the way, it is an argument added to options, ・ --Headless mode (It will not work unless it is executed with this) ・ --No-sandbox is required for google-chrome-stable to work (You can see it by running google-chrome-stable) ・ --Disable-gpu seems to stabilize the drawing area (The png file created when I ran it without this was black) ---Window-size is the same as specifying the window size It will be.

Finally

The created test.png was as follows. The characters are not garbled. test.png I thought there would be a big change in the migration to Amazon Linux 2, but it seems that it will not affect that much.

Recommended Posts

Build a Selenium environment on Amazon Linux 2 in the shortest time
How to build a Python environment on amazon linux 2
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Build an LNPP environment on Amazon Linux 2
[Linux] Build a Docker environment with Amazon Linux 2
Build a LAMP environment in a very short time
Set a fixed IP in the Linux environment
Build Azure Pipelies with Azure DevOps in a Linux self-hosted environment
Create a Linux environment on Windows 10
Build a python3 environment on CentOS7
Introduce Python 3.5.2 environment on Amazon Linux
On Linux, the time stamp of a file is a little past.
Build a python environment on MacOS (Catallina)
Build a simple WebDAV server on Linux
Build a Samba server on Arch Linux
Build WordPress on CentOS 8 in LAMP environment
[Linux] Build a jenkins environment with Docker
Build a Python + OpenCV environment on Cloud9
Install rJava on Linux in R3.6 environment.
Make Pandas available on Jupyter in the shortest possible time on your new Mac without polluting the environment
Make a list of "Houbunsha 70th Anniversary Campaign" on Selenium in Amazon
Procedure for building a kube environment on amazon linux2 (aws) ~ (with bonus)
I measured the run queue wait time of a process on Linux
Build Linux on a Windows environment. Steps to install Laradock and migrate
Build a LAMP environment on your local Docker
Build a WardPress environment on AWS with pulumi
Open a ZIP created on Windows in Linux
Use the latest pip in a virtualenv environment
Simply build a Python 3 execution environment on Windows
Build a Django environment on Raspberry Pi (MySQL)
Build a python environment with ansible on centos6
Build a Python environment on Mac (Mountain Lion)
Build a Django environment with Vagrant in 5 minutes
Build a Python development environment on your Mac
Build a Kubernetes environment for development on Ubuntu
Build a Minecraft plugin development environment in Eclipse
How to build Java environment on Ubuntu (Linux)
Build a mruby development environment for ESP32 (Linux)
Build a Python development environment on Raspberry Pi
Build an Arch Linux environment on Raspberry Pi
9 Steps to Become a Machine Learning Expert in the Shortest Time [Completely Free]
[Linux] Difference in time information depending on the clock ID of the clock_gettime () function
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a Django development environment using pyenv-virtualenv on Mac
Specify the volume on linux and make a sound
The story of building the fastest Linux environment in the world
Build a local development environment for Laravel6.X on Mac
Register a task in cron for the first time
The shortest route to get a cultural fish environment
Create a QR code for the URL on Linux
Build a machine learning Python environment on Mac OS
[Part 2] Let's build a web server on EC2 Linux
Build a GVim-based Python development environment on Windows 10 (1) Installation
How to build a Django (python) environment on docker
Build a Python development environment on Mac OS X
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Linux kernel build time
Create an environment for MkDocs on Amazon Linux (attempted)
Build a Python environment on your Mac using pyenv