[PYTHON] Screenshots of Megalodon in selenium and Chrome.

*** I took a screenshot of Megalodon with selenium and Chrome ***. *** It's a story *** ...

  1. The method of taking screenshots in Python is on the net, so I will omit it.
  2. The general public does not know how to operate the browser automatically using selenium. If you are an IT engineer, if you do not know how to do it, but you know its existence I think there are many, so I will omit this as well.

If you are local with the source code below I think you can take screenshots, *** You don't even need a virtual display ***. If you do it on the server, Japanese will be garbled with tofu type characters. I have to enter the Japanese font format. You need to be careful only there.

demo.py


# coding:utf-8
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import chromedriver_binary

from pyvirtualdisplay import Display

display = Display(visible=0, size=(1380,1124))
#Launch virtual display
display.start()

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--lang=ja-JP')
options.add_argument('--window-size=1280,1024')
#Launch Chrome
browser = webdriver.Chrome(options=options)
#Open the site you want to view
browser.get("https://megalodon.jp/")
#Take a screenshot of the site you viewed
browser.save_screenshot('screen.png')
sleep(2)
#Close browser
browser.close()
#Close virtual display
display.stop()

https://megalodon.jp/ screen.png

Recommended Posts

Screenshots of Megalodon in selenium and Chrome.
Selenium-Screenshot is useful for screenshots of web pages in Python3, Selenium and Google Chrome
Tips for using Selenium and Headless Chrome in a CUI environment
Separation of design and data in matplotlib
Summary of modules and classes in Python-TensorFlow2-
Drag and drop screenshots of dual screens
Project Euler # 1 "Multiples of 3 and 5" in Python
Summary of OSS tools and libraries created in 2016
Automatic operation of Chrome with Python + Selenium + pandas
Try running Google Chrome with Python and Selenium
phantomjs and selenium
View Selenium screenshots in Jupyter without saving files
Header shifts in read_csv () and read_table () of Pandas
Coexistence of Anaconda 2 and Anaconda 3 in Jupyter + Bonus (Julia)
Frequently used methods of Selenium and Beautiful Soup
Patch for taking full size screenshots in Chrome
Explanation of edit distance and implementation in Python
[Selenium] Open the link in a new tab and move it [Python / Chrome Driver]
"Linear regression" and "Probabilistic version of linear regression" in Python "Bayesian linear regression"
Full-width and half-width processing of CSV data in Python
About import error of numpy and scipy in anaconda
Calculation of standard deviation and correlation coefficient in Python
Note the frequently used options in Python + Selenium + Chrome
Difference between Ruby and Python in terms of variables
How to download files from Selenium in Python in Chrome
Automate Chrome with Python and Selenium on your Chromebook
Overview of generalized linear models and implementation in Python
Sample of getting module name and class name in Python
Summary of date processing in Python (datetime and dateutil)
Understand in 10 minutes Selenium
Selenium running in 15 minutes
Hot backup and restore of virtual machines in Hyper-V Server 2019
Types of preprocessing in natural language processing and their power
Applied practice of try/except and dictionary editing and retrieval in Python
What I'm glad I studied in 2015 and what I'm thinking of learning in 2016
[Reinforcement learning] Explanation and implementation of Ape-X in Keras (failure)
Reference order of class variables and instance variables in "self. Class variables" in Python
Comparison of how to use higher-order functions in Python 2 and 3
[Selenium] Print without header and footer (forced) [Python / Chrome Driver]
[Python] Strengths and weaknesses of DataFrame in terms of time required
[Tips] Problems and solutions in the development of python + kivy
Handling of HSV color space lower and upper in OpenCV
Coordination of each process in MPI and buffering of standard output
Explanation of CSV and implementation example in each programming language