Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to Solve normal image captcha Why ? #105

Open
lavkushry1 opened this issue Jul 20, 2024 · 2 comments
Open

Not able to Solve normal image captcha Why ? #105

lavkushry1 opened this issue Jul 20, 2024 · 2 comments

Comments

@lavkushry1
Copy link

def solve_captcha_with_retries(driver, max_attempts=5, min_successful=2):
solver = TwoCaptcha(API_KEY)
successful_solves = 0
attempt = 0
while attempt < max_attempts and successful_solves < min_successful:
try:
captcha_img_src = driver.find_element(By.ID, "captcha").get_attribute("src")
response = requests.get(captcha_img_src)
if response.status_code == 200:
with open('captcha.jpg', 'wb') as file:
file.write(response.content)
captcha_result = solver.normal('captcha.jpg')
if 'code' in captcha_result:
captcha_solution = captcha_result['code']
captcha_input = driver.find_element(By.NAME, "answer")
captcha_input.clear() # Ensure the input field is empty before entering the solution
captcha_input.send_keys(captcha_solution)
os.remove('captcha.jpg')
successful_solves += 1
if successful_solves >= min_successful:
logging.info(f"CAPTCHA solved successfully {successful_solves} times.")
return True
else:
logging.error(f"Captcha result did not contain 'code': {captcha_result}")
else:
logging.info(f"Attempt {attempt + 1}: Failed to download CAPTCHA image. Retrying...")
except Exception as e:
logging.error(f"Attempt {attempt + 1}: Error solving CAPTCHA: {e}")
finally:
attempt += 1
if successful_solves < min_successful:
logging.error("Failed to achieve the minimum number of successful CAPTCHA solves.")
return False
return True

@lavkushry1
Copy link
Author

simpleCaptcha
only this CAPTCHA

@Damji7
Copy link

Damji7 commented Aug 31, 2024

try this method , well am using the seleniumbase with 2captcha.

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR API')
solver = TwoCaptcha(api_key)

def check_captcha(sb):
if sb.is_element_visible('#CaptchaImage'):
captcha_image = sb.get_element('#CaptchaImage')
sb.execute_script("arguments[0].scrollIntoView(true);", captcha_image)
captcha_image.screenshot('the_captcha.png')
break_captchasuisse()
sb.sleep(4)

    try:
        result = solver.normal('the_captcha.png')
    except Exception as e:
        print(e)
    else:
        code = result['code']
        print(code)
        #code = code.upper() #Use this if you want to type the code in upper case, it depends on this captcha how its generated for you
        sb.type("#CaptchaInputText", code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants