diff --git a/README.md b/README.md index abd2e38..8a12b41 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,19 @@ CAPTCHA_API_KEY=your_api_key TARGET_URL=https://your-site.example/captcha-page ``` -> Before running an example, replace `TARGET_URL` with the target page for your -> own authorized test. Do not leave the placeholder value. Each example expects -> the page to contain the corresponding captcha type and may require its -> selectors or callback names to be adjusted for that page. +> Before running an example other than `recaptcha_v2.py`, replace `TARGET_URL` +> with the target page for your own authorized test. Do not leave the placeholder +> value. Each example expects the page to contain the corresponding captcha type +> and may require its selectors or callback names to be adjusted for that page. + +The reCAPTCHA v2 example is ready to run without setting `TARGET_URL`: + +```bash +python examples/recaptcha_v2.py +``` + +It uses the official public reCAPTCHA demo by default. Set `TARGET_URL` only if +you want to run it against another authorized page. Run an example from the repository root: diff --git a/examples/recaptcha_v2.py b/examples/recaptcha_v2.py index 3370728..f1c013d 100644 --- a/examples/recaptcha_v2.py +++ b/examples/recaptcha_v2.py @@ -1,14 +1,21 @@ """Solve reCAPTCHA v2 in a SeleniumBase browser session.""" +import os import time from captcha_solver_api.tasks import RecaptchaV2TaskProxyless -from common import create_client, fill_response_field, required_env, show_success, wait_for_xpath +from common import ( + create_client, + fill_response_field, + wait_for_css, + wait_for_xpath, +) from seleniumbase import Driver -URL = required_env("TARGET_URL") -SITEKEY_LOCATOR = "//div[@id='g-recaptcha']" -SUBMIT_LOCATOR = "//button[@data-action='demo_action']" +URL = os.getenv("TARGET_URL") or "https://www.google.com/recaptcha/api2/demo" +SITEKEY_LOCATOR = "//*[@data-sitekey]" +SUBMIT_LOCATOR = "//*[@type='submit']" +SUCCESS_SELECTOR = ".recaptcha-success, p.successMessage" def main() -> None: @@ -28,7 +35,7 @@ def main() -> None: ) fill_response_field(driver, "g-recaptcha-response", solution["gRecaptchaResponse"]) wait_for_xpath(driver, SUBMIT_LOCATOR).click() - show_success(driver) + print(wait_for_css(driver, SUCCESS_SELECTOR).text) time.sleep(5)