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

Idea #107

Closed
alluding opened this issue Jun 23, 2024 · 2 comments
Closed

Idea #107

alluding opened this issue Jun 23, 2024 · 2 comments

Comments

@alluding
Copy link

No clue if this is possible. I mean, it was logical enough to work with a Cloudflare turnstile solver. Couldn't you use the reCaptcha challenge URI (given by a user) and build a separate page (local) with just the captcha? As of now, this is limited to pages where the captcha is visible without needing to do other actions. What I'm suggesting would, I mean, logically erase this limitation, as you could solve the captcha without requiring the other actions.

@Xewdy444
Copy link
Owner

You can do something like this:

from playwright.sync_api import sync_playwright

from playwright_recaptcha import recaptchav2

RECAPTCHA_HTML = """
<!DOCTYPE html>
<html>
    <head>
        <script src="https://www.google.com/recaptcha/api.js" async
            defer></script>
    </head>
    <body>
        <div
            class="g-recaptcha"
            data-sitekey="{sitekey}"></div>
    </body>
</html>
"""


def main() -> None:
    with sync_playwright() as playwright:
        browser = playwright.firefox.launch()
        page = browser.new_page()
        page.goto("https://www.google.com")

        page.set_content(
            RECAPTCHA_HTML.format(sitekey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-")
        )

        with recaptchav2.SyncSolver(page) as solver:
            token = solver.solve_recaptcha(wait=True)
            print(token)


if __name__ == "__main__":
    main()

The one requirement is that you load a website with the page before setting the reCAPTCHA HTML. If you don't, you'll get this error:
image

@Xewdy444
Copy link
Owner

Xewdy444 commented Jul 2, 2024

Added an example for this

@Xewdy444 Xewdy444 closed this as completed Jul 2, 2024
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