Skip to content

RC-3138 #5

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

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Set the `APIKEY` environment variable. You can get the `APIKEY` value in your pe

`export APIKEY=your_api_key`

You can also set the value of `APIKEY` directly in the code. To do this, modify the `apikey` value in the following file: [main.py, line 10].

### Example Command
```bash
python main.py
Expand Down Expand Up @@ -87,6 +89,7 @@ The project follows a modular design for better maintainability:
[selenium]: https://pypi.org/project/selenium/
[2captcha-python]: https://github.com/2captcha/2captcha-python
[reCAPTCHA Solver using 2Captcha and Puppeteer]: https://github.com/2captcha/puppeteer-recaptcha-solver-using-clicks
[main.py, line 10]: ./main.py#L10
[reCAPTCHA]: https://2captcha.com/p/bypass-recaptcha


42 changes: 23 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
solver = TwoCaptcha(apikey, pollingInterval=1)

# LOCATORS
l_iframe_captcha = "//iframe[@title='reCAPTCHA']"
l_checkbox_captcha = "//span[@role='checkbox']"
l_popup_captcha = "//iframe[contains(@title, 'two minutes')]"
l_verify_button = "//button[@id='recaptcha-verify-button']"
l_submit_button_captcha = "//button[@type='submit']"
l_try_again = "//div[@class='rc-imageselect-incorrect-response']"
l_select_more = "//div[@class='rc-imageselect-error-select-more']"
l_dynamic_more = "//div[@class='rc-imageselect-error-dynamic-more']"
l_select_something = "//div[@class='rc-imageselect-error-select-something']"

# CAPTCHA LOCATORS
c_iframe_captcha = "//iframe[@title='reCAPTCHA']"
c_checkbox_captcha = "//span[@role='checkbox']"
c_popup_captcha = "//iframe[contains(@title, 'two minutes')]"
c_verify_button = "//button[@id='recaptcha-verify-button']"
c_try_again = "//div[@class='rc-imageselect-incorrect-response']"
c_select_more = "//div[@class='rc-imageselect-error-select-more']"
c_dynamic_more = "//div[@class='rc-imageselect-error-dynamic-more']"
c_select_something = "//div[@class='rc-imageselect-error-select-something']"

# PAGE LOCATORS (For another page the value of this locator needs to be changed)
p_submit_button_captcha = "//button[@type='submit']"

# MAIN LOGIC
options = webdriver.ChromeOptions()
Expand All @@ -34,10 +38,10 @@
captcha_helper = CaptchaHelper(browser, solver)

# We start by clicking on the captcha checkbox
page_actions.switch_to_iframe(l_iframe_captcha)
page_actions.click_checkbox(l_checkbox_captcha)
page_actions.switch_to_iframe(c_iframe_captcha)
page_actions.click_checkbox(c_checkbox_captcha)
page_actions.switch_to_default_content()
page_actions.switch_to_iframe(l_popup_captcha)
page_actions.switch_to_iframe(c_popup_captcha)
time.sleep(1)

# Load JS files
Expand Down Expand Up @@ -102,13 +106,13 @@
continue # Continue the loop

# Press the check button after clicks
page_actions.click_check_button(l_verify_button)
page_actions.click_check_button(c_verify_button)

# Processing for 4x4
elif params['cols'] == 4:
# Click on the answers found and immediately press the check button
page_actions.clicks(number_list)
page_actions.click_check_button(l_verify_button)
page_actions.click_check_button(c_verify_button)

# After clicking, we check for errors and image updates
image_update = page_actions.check_for_image_updates()
Expand All @@ -118,22 +122,22 @@
continue # Continue the loop

# If the images are not updated, check the error messages
if captcha_helper.handle_error_messages(l_try_again, l_select_more, l_dynamic_more, l_select_something):
if captcha_helper.handle_error_messages(c_try_again, c_select_more, c_dynamic_more, c_select_something):
continue # If an error is visible, restart the loop

# If there are no errors, send the captcha
page_actions.switch_to_default_content()
page_actions.click_check_button(l_submit_button_captcha)
page_actions.click_check_button(p_submit_button_captcha)
break # Exit the loop if the captcha is solved

elif 'no_matching_images' in result['code']:
# If the captcha returned the code "no_matching_images", check the errors
page_actions.click_check_button(l_verify_button)
if captcha_helper.handle_error_messages(l_try_again, l_select_more, l_dynamic_more, l_select_something):
page_actions.click_check_button(c_verify_button)
if captcha_helper.handle_error_messages(c_try_again, c_select_more, c_dynamic_more, c_select_something):
continue # Restart the loop if an error is visible
else:
page_actions.switch_to_default_content()
page_actions.click_check_button(l_submit_button_captcha)
page_actions.click_check_button(p_submit_button_captcha)
break # Exit loop

time.sleep(10)