--Run Google Chrome headless and take screenshots --Using Ubuntu on AWS EC2
Only the command is written, but if you want to check the result, write it with a prompt like $ command
.
--From EC2, start ʻUbuntu Server 18.04 LTS (HVM) 64-bit` --ssh Log in and check
$ cat /etc/issue
Ubuntu 18.04.4 LTS \n \l
--Set src
directly under home (appropriate)
--Basically, this directory is the current directory.
mkdir src
cd src
Download and install the deb package
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
Install dependent modules with apt
sudo apt update
sudo apt -f install -y
Installation confirmation
$ which google-chrome
/usr/bin/google-chrome
Install with apt
sudo apt install python3-selenium
It seems that Chrome Driver will also be installed
$ which chromedriver
/usr/bin/chromedriver
Install unzip before that
sudo apt install unzip
Download and extract (specify the file name)
wget https://ipafont.ipa.go.jp/IPAexfont/IPAexfont00401.zip
unzip IPAexfont00401.zip -d ~/.fonts/
Font cache clear
fc-cache -fv
Check the result of the fc-cache command (user home part)
(snip)
/home/ubuntu/.fonts/IPAexfont00401: caching, new cache contents: 2 fonts, 0 dirs
(snip)
fc-cache: succeeded
getss.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = '/usr/bin/google-chrome'
options.add_argument('--headless')
options.add_argument('--window-size=1280,1024')
driver = webdriver.Chrome('chromedriver', chrome_options=options)
driver.get('https://ja.wikipedia.org/wiki/Google_Chrome')
driver.save_screenshot('./screenshot.png')
driver.quit()
Run
python3 getss.py
You can confirm that Japanese is also displayed correctly (Arabic characters? Etc. are not displayed)
Recommended Posts