I have been scraping this site: https://www.immobilienscout24.de
When opening the site with selenium, the site sometimes gives you to solve a puzzle captcha after you have clicked you are not a robot captcha. The thing is that the site lets you only move the puzzle 6 times. If you fail to put the puzzle in the right place after the 6th time is bans you from entering the site.
The code moves the puzzle, but how would I arrange the for loop to split the screen into 6 exact pieces? Or if someone has some kind of different approach?
The code for the puzzle captcha is the following:
try:
slider = driver.find_element(By.CLASS_NAME, 'geetest_slider_button')
for x in range(0, 200, 10):
actions.move_to_element(slider).click_and_hold().move_by_offset(x, 0).release().perform()
time.sleep(0.1)
except:
print('No slider found. Continuing with the code.')
Thank you.
based on my understanding of your question, your goal is to validate a picture captcha within six attempts.
This is a very complex issue, and I believe the best solution would be to directly hand the images over to AI for image sequencing, which would be easier. However, I do not have the qualifications to call the relevant AI APIs. Maybe you can try to activate them. As for the code to call the AI, I don't think that would be difficult.
Excluding the possibility of using AI, I believe that attempting to achieve your goal through just simulated drag-and-drop will not be successful.
First, you need to capture the captcha area by whatever means necessary, eventually obtaining six disordered images. For instance, you could capture a single disordered image and then slice it locally, or directly fetch the image resources from the web page's source code.
Assuming you've reached this step and obtained six images, you can then proceed to merge them and perform image sampling. There are many ways to sample, such as first setting the images to grayscale and then performing contour extraction. This way, you get a contour map. Generally, as there is a gradient in brightness in a single image, there will be clear dividing lines between images. Of course, to get these distinct feature lines, you may need to constantly change the parameters during contour extraction. However, since the images have already been downloaded locally, you can still brute force this problem.
Mostly, we cannot achieve a 100% match in edge testing, so you need to establish feature values for each edge matching result. After completing all permutations and combinations of the sequence, use the highest feature value to move the images. If there are still attempts left, you can continue to use a lower-ranked sequence.
You might ask how to establish feature values when you don't have an absolutely correct image for edge matching comparison. My thinking is that you could reverse your approach. For example, manually create a blank image and artificially draw contrasting lines at the positions of the dividing lines. After that, extract the contours of this image to serve as a reference for your feature values.
Additionally, another thought is to apply an edge matching algorithm directly to the six images, match them in pairs, and calculate the final matching value.
The above is my thought process, and below could be the potential code involved in that process.