最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Problem with log in on discord with captcha using selenium - Stack Overflow

programmeradmin1浏览0评论

I want to create a bot who log in discord. The problem is that discord appear with a captcha. I paid for 2captcha solution.

I solve the captcha but I don't know how to insert it because there are no button. There are iframe and I am not sure how to do.

I try several code but I am novice.

Can you help me to find a way to do that?

I am so helpful.

I can answer quickly.

Thanks a lot.

driver.get(";)
driver.set_window_size(1080, 1024)


WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "email")))

driver.find_element(By.NAME, "email").send_keys(DISCORD_EMAIL)
time.sleep(1)
driver.find_element(By.NAME, "password").send_keys(DISCORD_PASSWORD)
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click()

try:
    captcha_iframe = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, 'iframe[data-hcaptcha-widget-id]'))
    )

    site_key = driver.execute_script("return document.querySelector('iframe').src.split('sitekey=')[1].split('&')[0]")
    print("site key OK")

    #driver.switch_to.default_content()

    captcha_token = solve_captcha(site_key, ";)

    time.sleep(3)

    driver.execute_script(f"""
        const iframe = document.querySelector('iframe[data-hcaptcha-widget-id]');
        console.log('Iframe:', iframe);
        if (!iframe) {{
            console.log('Iframe not found');
            return;
        }}
        const parent = iframe.parentElement.parentElement;
        console.log('Parent:', parent);
        if (!parent) {{
            console.log('Parent element not found');
            return;
        }}
        const reactPropsKey = Object.keys(parent).find(key => key.includes('reactProps'));
        console.log('reactPropsKey:', reactPropsKey);
        if (!reactPropsKey) {{
            console.log('reactProps key not found');
            return;
        }}
        if (!parent[reactPropsKey] || !parent[reactPropsKey].children || !parent[reactPropsKey].children.props || !parent[reactPropsKey].children.props.onVerify) {{
            console.log('onVerify function not found');
            console.log(parent[reactPropsKey]);
            return;
        }}
        parent[reactPropsKey].children.props.onVerify('{captcha_token}');
        console.log('Captcha verified successfully');
    """)

    time.sleep(2)

    # Capture console logs
    logs = driver.get_log('browser')
    for log in logs:
        print(log)
发布评论

评论列表(0)

  1. 暂无评论