My Code below is keep solving a different Captcha ! Please correct my mistake as i don't know what's causing that!
from selenium import webdriver
from python3_anticaptcha import ImageToTextTask, CallbackClient
import time
import requests
browser = webdriver.Firefox()
url = 'https://urlmased.com/'
browser.get(url)
time.sleep(10)
username = browser.find_element_by_id("masked")
username.send_keys("testuser")
password = browser.find_element_by_id("masked")
password.send_keys("testpass")
image_link = browser.find_element_by_xpath(
'//*[@id="masked"]').get_attribute('src')
pic = requests.get(image_link)
if pic.status_code == 200:
with open("image.png", 'wb') as f:
f.write(pic.content)
ANTICAPTCHA_KEY = 'masked'
captcha_file = "image.png"
result = ImageToTextTask.ImageToTextTask(
anticaptcha_key=ANTICAPTCHA_KEY).captcha_handler(captcha_file=captcha_file)
captcha = browser.find_element_by_id("masked")
captcha.send_keys(result['solution']['text'])
login = browser.find_element_by_id("yw2")
Be Informed that the API is active so you can use it till you reach a solution. and then i will change it.
Also the accuracy of solving is 100%
The issue here is that the captcha URL in the page source is not an actual image URL. It's a script to dynamically generate captcha images there for when you use the captcha solver API you are solving a defferent image than the browser loaded. To solve this we have to save the same image the browser loaded. I traced the image request and found out, it's using unique cookies that was generated when the browser loaded the page.
Using Selenium:
Using Requests and Beautiful soup: the following is the idea not sure if it's working you will have to test yourself: