Xewdy444 / Playwright-reCAPTCHA

A Python library for solving reCAPTCHA v2 and v3 with Playwright
https://pypi.org/project/playwright-recaptcha/
MIT License
240 stars 33 forks source link

Google login captchas solving #25

Closed florinb-cyberhaven closed 1 year ago

florinb-cyberhaven commented 1 year ago

Hey and first of all good job on trying to solve those captcha problems. I tried both recaptchav2 and recaptchav3 for the google login flow and none worked. Any ideas how to solve this one? Thank you! image

The api request looks like this: https://accounts.google.com/Captcha?v=2&ctoken=AAWk9lQmxc2mqQGWcUrhHHacb8fogK0R6wGYLty5tKC0srS_mLrKbxQCIW6WykE9gU7k49WRaU4XC1R2X2MuYXVler7crvY0C5BKSs-tG3pMLDmm8ebjRTMmG2aoSSqmzZ6ANjjqBfg9HRl_FG8h9E8HAmcjoeH-IT8FGqHixezooAjx83PSBTCzhgFM-2o35xdTuMc1qGUB&kind=audio

Xewdy444 commented 1 year ago

Hello, this CAPTCHA is not a reCAPTCHA, which is what this library is for. If you need to be signed into a Google account to perform certain actions, I would suggest loading the Google account session cookies into the Playwright browser.


Here is an example of how you could do this:

from typing import Any, Dict, List

import browser_cookie3
from playwright.sync_api import sync_playwright

def get_browser_cookies() -> List[Dict[str, Any]]:
    # Sign into Google on a browser of your choice and extract the cookies from it using browser_cookie3.
    # Here I am using Brave.
    cookie_jar = browser_cookie3.brave()

    cookies = [
        {
            "name": cookie.name,
            "value": cookie.value,
            "domain": cookie.domain,
            "path": cookie.path,
            "secure": bool(cookie.secure),
        }
        for cookie in cookie_jar
    ]

    return cookies

def main() -> None:
    with sync_playwright() as playwright:
        browser = playwright.firefox.launch(headless=False)

        context = browser.new_context()
        context.add_cookies(get_browser_cookies())

        page = context.new_page()
        page.goto("https://mail.google.com/mail", wait_until="networkidle")

if __name__ == "__main__":
    main()
florinb-cyberhaven commented 1 year ago

Wow, thanks for the suggestion, works flawlessly on my local machine Not sure if it will on work on the CI env where I can't do this step: (Sign into Google on a browser of your choice and extract the cookies from it using browser_cookie3). Maybe if I run get_browser_cookies on a machine where I'm already logged in and export the cookies JSON to the CI env

Xewdy444 commented 1 year ago

Yep, that would work perfectly fine.