Python Forum
Automate screenshots taking and paste it to a web form
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automate screenshots taking and paste it to a web form
#1
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.

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
deanhystad write Nov-18-2023, 04:43 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What script to paste folders thenewcoder 1 703 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  Please help me [copy and paste file from src to dst] midomarc 2 1,060 Nov-24-2022, 10:13 PM
Last Post: midomarc
  Is it possible to open windows and do screenshots with Python? cubangt 2 1,385 Jan-14-2022, 03:57 PM
Last Post: cubangt
  ImageTk Paste KDog 14 7,072 Jun-27-2021, 11:07 AM
Last Post: KDog
  Cut and Paste Oshadha 3 2,486 Jan-20-2021, 04:27 PM
Last Post: spaceraiders
  copy paste file and re-name it asheru93 1 2,407 May-24-2019, 10:43 AM
Last Post: heiner55
  1. How can I automate this batch creation of documents? 2. How can I automate posting SamLearnsPython 2 3,471 Jul-02-2018, 11:36 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020