【问题标题】:Facing a problem in solving captcha using a service面临使用服务解决验证码的问题
【发布时间】:2020-11-22 19:58:27
【问题描述】:

我使用某种硬编码方法获取站点密钥,但由于 len 始终相同,所以没关系。 之后,我使用2captcha API Documentation,以便我可以发布密钥并获取验证码的令牌。我面临两个主要问题: 1)我总是收到站点密钥错误的错误,但根据他们的示例,站点密钥是正确的(他们的站点密钥长 40 个字符,我的站点密钥也是 40) 2)我尝试在外部创建一个 POST 函数并尝试它是否是一个错误,但是使用Py2Captcha 文档我总是收到以下错误: 这是验证码抓取。

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Captcha Key~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
url=driver.find_element_by_css_selector("iframe[role='presentation']").get_attribute('src')
print(url)
keygoogle = url[53:93]
print('Site Key = ', keygoogle)

这是解决验证码的关键块:

answer = ""
answer_id = 0
api_key = '--------------------------------'
data_post = {'key': api_key, 'method': 'userrecaptcha', 'googlekey': keygoogle, "pageurl": mainurl}
response = requests.post(url = 'https://2captcha.com/in.php', data = data_post )
print(response)
print("Waiting for server response.")
for x in range(15):
    time.sleep(1)
    if x == 5:
        print('Downloading info..')
    elif x == 10:
        print('Processing info..')
    elif x == 14:
        print('Solving captcha..')
data_request = {
    'key': api_key,
    'action': answer,
    'id': answer_id,
}
requests.get(url ='https://2captcha.com/res.php', data=data_request)
print(answer)

def captcha():
    google_key = keygoogle
    url = mainurl
    client = TwoCaptchaClient(client_key=api_key)
    task = GoogleReCaptchaV2Task(googlekey=google_key, pageurl=mainurl)
    job = client.create_task(task)
    token = job.get_solution_response()
    return token
print(captcha())

我没有包括将令牌发布到答案字段中的部分,我不知道该怎么做,但我一定会找到方法!

编辑: 这是我从打印得到的价值:

response = requests.post(url = 'https://2captcha.com/in.php', data = data_post )

这是我从print('Site Key = ', keygoogle)得到的值

站点密钥 = Lc3HAsUAAAAACsN7CgY9MMVxo2M09n_e4heJEiZ&

【问题讨论】:

    标签: python selenium captcha


    【解决方案1】:

    这是我获取正确密钥的方式:

        url=driver.find_element_by_css_selector("iframe[role='presentation']").get_attribute('src')
    keygoogle = url[52:92]
    

    这是我的 POST 函数:

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Captcha Solve~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    answer = ""
    answer_id = 0
    data_post = {'key': api_key, 'method': 'userrecaptcha', 'googlekey': keygoogle, "pageurl": mainurl}
    response = requests.post(url = 'https://2captcha.com/in.php', data = data_post )
    response = response.text[3:]
    print("Waiting for server response.")
    for x in range(30):
        time.sleep(1)
        if x == 8:
            print('Downloading info..')
        elif x == 15:
            print('Processing info..')
    data_request = {'key': api_key,'id': int(response),'action': 'get'}
    response = requests.get(url='https://2captcha.com/res.php', params=data_request)
    token = response.text.split('|')[0]
    while response.text == 'CAPCHA_NOT_READY':
        print('Waiting for Capcha..')
        time.sleep(5)
        response = requests.get(url='https://2captcha.com/res.php', params=data_request)
        token = response
    print(token)
    

    【讨论】:

      【解决方案2】:

      该站点密钥末尾的 & 绝对不应该存在。使用正则表达式而不是您在索引中所做的事情。

      【讨论】:

        猜你喜欢
        • 2020-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-21
        • 1970-01-01
        • 2020-03-15
        • 2022-12-31
        • 2020-09-20
        相关资源
        最近更新 更多