iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🗂
Capturing Screenshots with Python
Due to audit compliance, it is necessary to store captures of specific screens every month.
To automate this routine task, I will perform page captures using Python so that I only need to run the program each month.
.py file
cap.py
import subprocess
appDic = {}
appDic['fileName1'] = 'https://xxxxxxx/articles/xxxxxxxxxxxxxxxxx1'
appDic['fileName2'] = 'https://xxxxxxx/articles/xxxxxxxxxxxxxxxxx2'
# Iterate through the appDic dictionary, extracting keys and values one by one
for appName, url in appDic.items():
# Print to the console for debugging and monitoring progress
print("key:" + appName + ", values:" + url)
# Opens the web page address stored in the variable 'url' using Google Chrome.
result = subprocess.run(['open', '-a', 'Google Chrome', url], capture_output=True, text=True)
# Pause for 3 seconds (waiting for the web page to load)
subprocess.run(['sleep', '3'], capture_output=True, text=True)
# Execute the macOS screencapture command to take a screenshot of the screen
subprocess.run(['screencapture', '-m', '-t', 'pdf', '/Users/xxxxxxxxxxxxx/Documents/xxxxxxxxxxx/' + appName + '.pdf'], capture_output=True, text=True)
Store this in a Python file.
Execution
$ python3 {the_relevant_py_file}
Running this will start the process.
Discussion