0

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
Jarvn
  • 43
  • 6
  • 1
    See this answer for saving pillow image to base64: https://stackoverflow.com/questions/31826335/how-to-convert-pil-image-image-object-to-base64-string – irdkwmnsb Oct 02 '22 at 00:25

0 Answers0