Skip to content

Commit

Permalink
Create solve_with_sitekey.py
Browse files Browse the repository at this point in the history
Xewdy444 committed Jul 2, 2024
1 parent 9e8a385 commit 7680dd6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/recaptchav2/solve_with_sitekey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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()

# It is important to load a website before setting the reCAPTCHA HTML.
# If you don't, the reCAPTCHA will give you an "Invalid domain for site key" error.
page.goto("https://www.google.com/", wait_until="commit")

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()

0 comments on commit 7680dd6

Please sign in to comment.