0

So I have this code in Python3 that scraps data from websites through object recongnition (I used this to automate the download process inside a flash player based website) and Selenium. The problem is that I'm stuck with this website that have a custom made Captcha where the user have to select the different image from the group and I don´t know how to download or get these images from the site in order to identify the different one, has anyone solved a problem like this? or have an idea on how to solve this captcha with any other technique or method?

This is the login that has the CAPTCHA

And here's the link to the site which is in spanish. The captcha basically says "Select the different image" https://portalempresas.sb.cl/login.php

Thanks!

1 Answers1

0

To download those images as png files you could do:

from io import BytesIO
from PIL import Image

# Download image function
def downloadImage(element,imgName):
    img = element.screenshot_as_png
    stream = BytesIO(img)
    image = Image.open(stream).convert("RGB")
    image.save(imgName)

# Find all the web elements of the captcha images    
image_elements = driver.find_elements_by_xpath("*//div[contains(@class,'captcha-image')]")

# Output name for the images
image_base_name = "Imagen_[idx].png"

# Download each image
for i in range(len(image_elements)):
    downloadImage(image_elements[i],image_base_name.replace("[idx]","%s"%i))    

Edit 1:

If you want to compare 2 images to see if they are equal you could try with this post

Edit 2:

Using the solution edited above, these are the results:

captcha1 captcha1 captcha1 captcha1 captha2

Nimantha
  • 6,405
  • 6
  • 28
  • 69
EnriqueBet
  • 1,482
  • 2
  • 15
  • 23