Nov-18-2023, 03:01 PM
Hi Good people. I have a manual process that I would like to automate using Python. Below are the steps
1. I have a Gsheet opened and active in my browser. I want to take a screenshot of a part of the Gsheet ( x, y, width, height = 100, 800, 100, 100) and copy it to the clipboard (later this will be pasted in to a web form)
2. In my Gsheet R12 cell has web URL. This URL will open a web form. Now I want to click on R12 web URL which will open a new tab
3. paste the screenshot to the web form
4. press ALT+S
So far I have managed to write below code which will take a screenshot of active window and save it to my PC.
Please help me on this
1. I have a Gsheet opened and active in my browser. I want to take a screenshot of a part of the Gsheet ( x, y, width, height = 100, 800, 100, 100) and copy it to the clipboard (later this will be pasted in to a web form)
2. In my Gsheet R12 cell has web URL. This URL will open a web form. Now I want to click on R12 web URL which will open a new tab
3. paste the screenshot to the web form
4. press ALT+S
So far I have managed to write below code which will take a screenshot of active window and save it to my PC.
import pyautogui from PIL import Image import subprocess import time import pyperclip import base64 def take_screenshot(x, y, width, height): try: screenshot = pyautogui.screenshot(region=(x, y, width, height)) timestamp = time.strftime("%Y%m%d_%H%M%S") filename = f"screenshot_{timestamp}.png" screenshot.save(filename) return filename except Exception as e: print(f"Error taking screenshot: {e}") return None def open_image_with_default_viewer(filename): try: # Open the image file with the default associated program on Windows subprocess.Popen(["start", "", filename], shell=True) except Exception as e: print(f"Error opening image: {e}") def copy_image_to_clipboard(image_path): try: with open(image_path, 'rb') as image_file: image_data = base64.b64encode(image_file.read()).decode('utf-8') pyperclip.copy(image_data) print("Image copied to clipboard") except Exception as e: print(f"Error copying image to clipboard: {e}") def main(): # Set the coordinates and dimensions of the area you want to capture x, y, width, height = 100, 800, 100, 100 # Take a screenshot and get the filename screenshot_filename = take_screenshot(x, y, width, height) if screenshot_filename: # Perform any additional processing if needed image = Image.open(screenshot_filename) # Example: image processing
Please help me on this