-1

I want to make an algorithm that takes a running program and automates processes in it. I chose Python because I already know how to move the mouse and input keyboard presses in it, but I am currently struggling to find a way to take a screenshot so the algorithm knows what is it doing. Is it possible to use some Python library to take a screenshot every 1 - 2 frames?

Viliam
  • 5
  • 1
  • 3
  • 2
    What have you tried or looked up so far? – Matt Pitkin Mar 10 '23 at 16:51
  • @Claudio Thank you so much! Even though i would like to get a shot of the window itself, this will work good enough. If this was an answer, i would mark it as the best. Thank you! – Viliam Mar 16 '23 at 16:27

2 Answers2

0

I would use the methods from the same library you're using for the automation. For example, using selenium you could do:

from selenium import webdriver

browser = webdriver.Firefox() # or any other
browser.get('http://www.google.com/')
browser.save_screenshot('screenie.png')

Source

Otherwise you can use another library:

import pyautogui
im = pyautogui.screenshot()
im.save("SS1.jpg")
fulcus
  • 47
  • 1
  • 10
0

There is an excellent screenshot library for Python out there:

https://pypi.org/project/mss/

outperforming by far any other known to me options for taking a screenshot from Python code.

Check out "Fast screenshot of a small part of the screen in Python" for more details and hints what are the other available options.

Claudio
  • 7,474
  • 3
  • 18
  • 48