How to take a screenshot of the Chrome screen (prevent it from cutting off in the middle)

background

I tried to take a screenshot automatically using Selenium, but no matter how large the size was specified, it was cut off at the screen size and I had a hard time getting the bottom of the scroll, so this is a memorandum.

What was used

chromedriver (matching the version of chrome you are using) selenium python

Correspondence method

It was OK if I added headless in options.

screenshot.py


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

if __name__ == "__main__":

    #Settings required for inseparable screenshots
    options = Options()
    options.add_argument('--headless')
    driver = webdriver.Chrome(options=options)

    #Specify a wider size
    driver.set_window_size(1400, 2000)

    #Specifying the capture destination
    driver.get(r'https://ja.wikipedia.org/wiki/Qiita')

    #Capture execution. Specify the save file.
    driver.save_screenshot('screenshot.png')

    driver.close()

Consideration

If you add headless in options, Chrome will not start. If you don't attach it, the screenshot will be cut off probably because when Chrome starts up, the height and width will be slightly modified according to the window width. .. .. When. Maybe so.

Recommended Posts

How to take a screenshot of the Chrome screen (prevent it from cutting off in the middle)
How to quickly count the frequency of appearance of characters from a character string in Python?
How to plot the distribution of bacterial composition from Qiime2 analysis data in a box plot
How to determine the existence of a selenium element in Python
How to check the memory size of a variable in Python
How to check the memory size of a dictionary in Python
How to get the vertex coordinates of a feature in ArcPy
[NNabla] How to remove the middle tier of a pre-built network
From the introduction of GoogleCloudPlatform Natural Language API to how to use it
[EC2] How to take a screen capture of your smartphone with selenium
[NNabla] How to add a quantization layer to the middle layer of a trained model
How to calculate the volatility of a brand
How to pass the execution result of a shell command in a list in Python
How to mention a user group in slack notification, how to check the id of the user group
To output a value even in the middle of a cell with Jupyter Notebook
[NNabla] How to get the output (variable) of the middle layer of a pre-built network
How to count the number of elements in Django and output to a template
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook
How to get a list of files in the same directory with python
How to save the feature point information of an image in a file and use it for matching
How to display the modification date of a file in C language up to nanoseconds
How to get the number of digits in Python
[Python3] Take a screenshot of a web page on the server and crop it further
Clear the cron.log regularly to prevent it from growing.
How to identify the element with the smallest number of characters in a Python list?
Take a screenshot of the LCD with Python-LEGO Mindstorms
I want to take a screenshot of the site on Docker using any font
How to download files from Selenium in Python in Chrome
How to check in Python if one of the elements of a list is in another list
[NNabla] How to add a new layer between the middle layers of a pre-built network
How to post a ticket from the Shogun API
How to take a captured image from a video (OpenCV)
A story about trying to introduce Linter in the middle of a Python (Flask) project
How to display the regional mesh of the official statistics window (eStat) in a web browser
How to create an instance of a particular class from dict using __new__ () in python
How to find the average amount of information (entropy) of the original probability distribution from a sample
How to pass the execution result of a shell command in a list in Python (non-blocking version)
[Ubuntu] How to delete the entire contents of a directory
How to find the optimal number of clusters in k-means
How to slice a block multiple array from a multiple array in Python
Log in to the fortigate (6.0) management screen from selenium-try to log out
How to use the __call__ method in a Python class
How to calculate the amount of calculation learned from ABC134-D
How to log in automatically like 1Password from the CLI
How to develop in a virtual environment of Python [Memo]
How to generate a query using the IN operator in Django
How to get the last (last) value in a list in Python
How to get a list of built-in exceptions in python
How to find the scaling factor of a biorthogonal wavelet
How to get a list of links from a page from wikipedia
How to get a quadratic array of squares in a spiral!
How to connect the contents of a list into a string
Take a screenshot in Python
[See in the photo] How a kaggle beginner can rank up from "novice" to "Contributor" in 10 minutes.
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
How to display a specified column of files in Linux (awk)
How to handle multiple versions of CUDA in the same environment
[sh] How to store the command execution result in a variable
How to implement Java code in the background of RedHat (LinuxONE)
How to know the internal structure of an object in Python
How to get all the possible values in a regular expression