Python ws-Selenium如何解决reCAPTCHA不可见问题

2024-10-03 19:28:16 发布

您现在位置:Python中文网/ 问答频道 /正文

Python+Selenium请在我登录时帮助我解决instacart.com网站上不可见的问题

解决验证码的代码。使用过的rucaptcha镜子(2captcha)。我已成功获取响应代码,但无法将其嵌入到网站中

def captcha_solution(site_key: str, url: str):
    key = "api_key"  # api key
    id = requests.post("https://rucaptcha.com/in.php", params={
        "key": key,
        "method": "userrecaptcha",
        "googlekey": site_key,
        "pageurl": url,
        "json": 1
    })

    capt_id = id.json()["request"]

    while True:
        response = requests.get("https://rucaptcha.com/res.php", params={
            "key": key,
            "action": "get",
            "id": capt_id
        })

        if response.text == 'CAPCHA_NOT_READY':
            time.sleep(3)
        else:
            break

    return response.text.split("|")[-1]

###########function call##############

site_key = '6LfgstgZAAAAAO_TzxqxqR8E8Fu16VqIs1mBtAKH'
url = 'https://www.instacart.com'
captcha = captcha_solution(site_key, url) # get captcha
browser.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "%s"' % (captcha)) # here I can not insert response to the site

谢谢你抽出时间


Tags: key代码httpscomidurlget网站