Skip to content
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
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
17 changes: 12 additions & 5 deletions examples/recaptcha_v2.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)


Expand Down
Loading