I want to take a screenshot of the whole page, crop out the captcha image and base64 encode the cropped image.
I know one way is to save the cropped image as a png to a folder but i'd like to know if there's any other way without saving it.
This is my current code:
from selenium import webdriver
from PIL import Image
from io import BytesIO
import time
browser = webdriver.Chrome(executable_path="C:/chromedriver")
browser.get("https://accounts.hcaptcha.com/demo?sitekey=93d2dffa-6cad-4031-9c00-4741a03c569d")
time.sleep(7)
# Click on hCaptcha checkbox within 7 seconds
img = browser.get_screenshot_as_png()
img = Image.open(BytesIO(img))
left = 89
top = 12
right = 490
bottom = 609
img = img.crop((left, top, right, bottom))
# base64 img