Hi guys we are bypassing the captcha by selenium web driver to log in particular webpage.
(Please note that this article does not condone or support any form of security bypass or unethical use of technology).
- OpenCV (cv2)
- Tesseract OCR
- Pillow (PIL)
Import the required modules as I shown below. from selenium import webdriver import cv2 from PIL import Image from pytesseract import pytesseract driver = webdriver() driver.maximize_window() # Now we will hit the website just pass your website link below. driver.get(" Your Website Link Here")
# Taking screenshot of login page and saving it as image.png driver.save_screenshot("image.png")
This is sample cropped image.
img = cv2.imread('image.png') # you guys have define coordinates as per your page layout. cropped_image = img[200:250, 60:200] cv2.imwrite("Cropped_Image.jpeg", cropped_image)
To extract text from the cropped image, we use Tesseract OCR. Make sure you have Tesseract installed and properly configured. We set the path to the Tesseract executable and the path to our cropped image.
# Define path to tesseract.exe path_to_tesseract = "Your path to tesseract.exe" # Define path to the cropped image path_to_image = "Your path to cropped image" # Point pytesseract to the Tesseract executable pytesseract.tesseract_cmd = path_to_tesseract img = Image.open(path_to_image) # Extract text from image text = pytesseract.image_to_string(img)
Now take that data in text variable and using send keys send it to captcha labelbox.
enetr_captcha = driver.find_element("element path to location").send_keys(text)
Please remember to use this knowledge responsibly and ethically. Accessibility is about making the digital world more inclusive, not compromising security.
In this blog post, we've explored how to use Python, OpenCV, and Tesseract OCR to extract text from images. While this technique has legitimate uses, it's essential to use such knowledge for the right purposes, such as improving web accessibility.
I hope this would be helpful if yes like and comments Yeehhhh!