Specify or create a python folder and then save the screenshot.

Conclusion

Directory generation is os.mkdir (path) Take a screenshot at pyautogui.screenshot () Screenshots are saved to save ("save to")

* Path specification method

Concrete example

All chords


import os
import pyautogui
import time
import datetime

#Save destination path
h_path = "Enter where you want to save the folder here" #For example, on a Mac/Users/"username"/Downloads/
#Number of screenshots(Times)
times = 3
#Screenshot interval(Seconds)
span = 1
#Output folder acronym
h_foldername = "Statistical analysis"
#Output file acronym
h_filename = "Document"

#Create output folder(Folder name: Initial_Year, month, day, hour and minute)
folder_name = h_foldername + "_" + str(datetime.datetime.now().strftime("%Y%m%d%H%M"))
path = h_path + folder_name
os.makedirs(path, exist_ok=True)

for i in range(times):

    #Give the image a name
    filename  = h_filename + '_{0:04d}.png'.format(i)+ "_" + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))

    #Take a screenshot
    s = pyautogui.screenshot()

    #Save
    s.save(folder_name + '/' + filename)

    #Screenshot interval(Seconds)
    time.sleep(span)


Supplement

I used .format (number) to use 4-digit notation when numbering image files. {0:04d}'.format(number) ・ Fill with 0: 0 ・ 04d: 4 digits

Example(10→0010)


number = 10
number_padded = '{0:04d}'.format(number)
print(number_padded)  # => '0010'


Reference

I learned a lot here. [Introduction to Python] Creating a directory easily | os.mkdir ・ os.makedirs [Python] I made a tool to automatically screenshot Kindle books using pyautogui!

Recommended Posts

Specify or create a python folder and then save the screenshot.
Create a partition and then install the Raspberry Pi OS
[Python] return A [or / and] B
Connect a lot of Python or and and
ffmpeg-Build a python environment and split the video
Create a web map using Python and GDAL
Create a Mac app using py2app and Python3! !!
A discussion of the strengths and weaknesses of Python
Create a Python image in Django without a dummy image file and test the image upload
Create a simple reception system with the Python serverless framework Chalice and Twilio
Create a Django project and application in a Python virtual environment and start the server
[Python] Take a screenshot
[Python3] Take a screenshot of a web page on the server and crop it further
Create a Python module
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
Create a Python environment
Create a decent shell and python environment on Windows
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
Create a docx file with thumbnails of photos in the folder pasted with the Python python-docx library and the free software "Reduction only."
Shuffle the images in any directory with Python and save them in another folder with serial numbers.
Recursively get the Excel list in a specific folder with python and write it to Excel.
Parse the Researchmap API in Python and automatically create a Word file for the achievement list
Save the pystan model and results in a pickle file
Create a local scope in Python without polluting the namespace
Temporarily save a Python object and reuse it in another Python
Probably the easiest way to create a pdf with Python3
[Python] Create a date and time list for a specified period
Let's create a PRML diagram with Python, Numpy and matplotlib.
Create a Twitter BOT with the GoogleAppEngine SDK for Python
Build a Python environment and transfer data to the server
Create code that outputs "A and pretending B" in python
Python: Create a dictionary from a list of keys and values
[Python3] "A // B" and "math.floor (A / B)" are not always the same! ??
Take a screenshot in Python
Create a Wox plugin (Python)
Create a function in Python
Create a dictionary in Python
Create a python numpy array
Python bitwise operator and OR
Create a directory with python
Python or and and operator trap
I made a simple circuit with Python (AND, OR, NOR, etc.)
Save the result of the life game as a gif with python
Process Splunk execution results using Python and save to a file
Create a shell script to run the python file multiple times
Create a color picker for the color wheel with Python + Qt (PySide)
Create a simple scheduled batch using Docker's Python Image and parse-crontab
[Ev3dev] Create a program that captures the LCD (screen) using python
[Python3] Save the mean and covariance matrix in json with pandas
Solve the Python knapsack problem with a branch and bound method
Create a CGH for branching a laser in Python (laser and SLM required)
Dig the directory and create a list of directory paths + file names
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
[Mac] Create a Python3 execution environment from the fully initialized state
Create a simple Python development environment with VS Code and Docker
Operate Firefox with Selenium from python and save the screen capture
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
Create a compatibility judgment program with the random module of python.