Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
实现2captcha、python和selenium时出现问题_Python_Selenium_Recaptcha_Captcha_2captcha - Fatal编程技术网

实现2captcha、python和selenium时出现问题

实现2captcha、python和selenium时出现问题,python,selenium,recaptcha,captcha,2captcha,Python,Selenium,Recaptcha,Captcha,2captcha,我在python selenium中实现2captcha时遇到问题。下面是代码。验证码无法解决。没有为我弹出错误,但验证码无法解决 import requests from time import sleep # Add these values API_KEY = '' # Your 2captcha API KEY site_key = '' # site-key, read the 2captcha docs on how to get this url = 'http://some

我在python selenium中实现2captcha时遇到问题。下面是代码。验证码无法解决。没有为我弹出错误,但验证码无法解决

import requests
from time import sleep

# Add these values
API_KEY = ''  # Your 2captcha API KEY
site_key = ''  # site-key, read the 2captcha docs on how to get this
url = 'http://somewebsite.com'  # example url
proxy = '127.0.0.1:6969'  # example proxy

proxy = {'http': 'http://' + proxy, 'https': 'https://' + proxy}

s = requests.Session()

# here we post site key to 2captcha to get captcha ID (and we parse it here too)
captcha_id = s.post("http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}".format(API_KEY, site_key, url), proxies=proxy).text.split('|')[1]
# then we parse gresponse from 2captcha response
recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id), proxies=proxy).text
print("solving ref captcha...")
while 'CAPCHA_NOT_READY' in recaptcha_answer:
    sleep(5)
    recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id), proxies=proxy).text
recaptcha_answer = recaptcha_answer.split('|')[1]

# we make the payload for the post data here, use something like mitmproxy or fiddler to see what is needed
payload = {
    'key': 'value',
    'gresponse': recaptcha_answer  # This is the response from 2captcha, which is needed for the post request to go through.
    }


# then send the post request to the url
response = s.post(url, payload, proxies=proxy)

这是请求库的2Captcha指南,不适用于selenium,可能它不适用于selenium,请尝试查看此页面,

这是请求库的2Captcha指南,不适用于selenium,可能它不适用于selenium,请尝试查看此页面