-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |