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

Captcha Solving API Support #55

Open
B1NT0N opened this issue May 16, 2024 · 8 comments
Open

Captcha Solving API Support #55

B1NT0N opened this issue May 16, 2024 · 8 comments

Comments

@B1NT0N
Copy link

B1NT0N commented May 16, 2024

Is your feature request related to a problem? Please describe.
Logging in became unreliable after some time, so I suggest an implementation of a captcha solving method.

Describe the solution you'd like
We could use a captcha solving API service to do so and improve login in consistency.

I'm willing to provide my 2captcha API key to help development.

@ranjan-mohanty
Copy link
Owner

Sounds like a good idea! Implementing a CAPTCHA solving API service can definitely improve login consistency.
And also your 2Captcha API key would be very helpful for development.

@B1NT0N
Copy link
Author

B1NT0N commented May 21, 2024

I've manage to get the data-sitekey attribute, but I'm having trouble sending the TOKEN to the input field.
Here is a snippet of the code:

div_selector = 'div.my-10'
page.wait_for_selector(div_selector)

# Get the div element
div_element = page.query_selector(div_selector)

# Get the iframe inside the div
iframe_selector = 'iframe'
iframe_element = div_element.query_selector(iframe_selector)

pattern = r'/0x([A-Za-z0-9_-]+)/'

# Use re.search to find the pattern in the URL
match = re.search(pattern, iframe_url)
extracted_info = match.group(1)

image

Here is the 2captcha Cloudflare Turnstile demo for context,
Please DM me for the API key

@Tasluf665
Copy link

I might think they used the Cloudflare Challenge page. Which is difficult to solve. Extracting the data-sitekey might not work here.

@B1NT0N
Copy link
Author

B1NT0N commented May 21, 2024

I might think they used the Cloudflare Challenge page. Which is difficult to solve. Extracting the data-sitekey might not work here.

I'm not seeing the Cloudflare Challenge page when accesing the website though, just what I belive to be the normal Cloudflare Turnstile challenge. But since I'm new to this I may be wrong

This is what I'm talking about:
image

@ranjan-mohanty
Copy link
Owner

I've manage to get the data-sitekey attribute, but I'm having trouble sending the TOKEN to the input field. Here is a snippet of the code:

div_selector = 'div.my-10'
page.wait_for_selector(div_selector)

# Get the div element
div_element = page.query_selector(div_selector)

# Get the iframe inside the div
iframe_selector = 'iframe'
iframe_element = div_element.query_selector(iframe_selector)

pattern = r'/0x([A-Za-z0-9_-]+)/'

# Use re.search to find the pattern in the URL
match = re.search(pattern, iframe_url)
extracted_info = match.group(1)

image

Here is the 2captcha Cloudflare Turnstile demo for context, Please DM me for the API key

Thanks for sharing! I will check it over the weekends and can you share the API keys over the email, if that's ok?

@PogProp
Copy link

PogProp commented Jun 25, 2024

I've managed to verify the Captcha with TwoCaptcha, get the token in result and fill the value in the input but it is not getting verified... It is still showing the checkbox "Verify you are a human"... I don't know why because when I use my normal browser (Chrome or Safari), it is automatically verified. Any update on that process @ranjan-mohanty? :)

`def check_captcha(self, page: Page) -> None:
"""
Performs captcha verification.

    Args:
        page (playwright.sync_api.Page): The Playwright page object used for browser interaction.
    """
    div_selector = 'div.my-10'
    page.wait_for_selector(div_selector)

    # Get the div element
    div_element = page.query_selector(div_selector)
    if not div_element:
        logging.error(f"Div element with selector '{div_selector}' not found.")
        return None

    # Get the iframe inside the div
    iframe_selector = 'iframe'
    iframe_element = div_element.query_selector(iframe_selector)
    if not iframe_element:
        logging.error(f"Iframe element with selector '{iframe_selector}' not found.")
        return None

    # Get the iframe URL
    iframe_url = iframe_element.get_attribute('src')
    if not iframe_url:
        logging.error("Iframe URL not found.")
        return None

    # Define the pattern to extract information from the URL
    pattern = r'/0x([A-Za-z0-9_-]+)/'

    # Use re.search to find the pattern in the URL
    match = re.search(pattern, iframe_url)
    if match:
        extracted_info = match.group(1)
        logging.debug(f"Extracted info: {extracted_info}")
        print(f"Extracted info: {extracted_info}")
        print(f"Page: {page.url}")
        result = solver.turnstile(sitekey=f"0x{extracted_info}", url=page.url)
        print(f"Result: {result}")
        if result and 'code' in result:
            captcha_token = result['code']
        
            page.evaluate(f'document.getElementsByName("cf-turnstile-response")[0].value="{captcha_token}";')
         
            return captcha_token
        else:
            logging.error("CAPTCHA solving failed or no code returned.")
            return None
    else:
        logging.error("Pattern not found in the iframe URL.")
        return None`

`from twocaptcha import TwoCaptcha

solver = TwoCaptcha('API_KEY')`

Screenshot 2024-06-25 at 9 52 17 AM

@piyushhanchate
Copy link

piyushhanchate commented Jul 11, 2024

@PogProp I'm facing the same issue. Were you able to solve this?

@PogProp
Copy link

PogProp commented Jul 11, 2024

No, still having this issue…

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

5 participants