首页 > 解决方案 > 通过 2captcha API 绕过 Yahoo reCAPTCHA

问题描述

我正在尝试使用 python selenium 创建 yahoo 帐户,并且在创建时我必须绕过 recaptcha。我正在使用 2Captcha API 来自动解决验证码

我的问题是我无法解决 recaptcha

根据我的测试,我注意到雅虎正在使用企业验证码,不确定它是 V2 还是 V3

这里是 API 文档:https ://2captcha.com/2captcha-api

这是我的代码:

import os
import time
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import random
from twocaptcha import TwoCaptcha

opt = Options()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
# Pass the argument 1 to allow and 2 to block
opt.add_experimental_option("excludeSwitches", ["enable-logging"])
opt.add_experimental_option("prefs", {
        "profile.default_content_setting_values.media_stream_mic": 2,
        "profile.default_content_setting_values.media_stream_camera": 2,
        "profile.default_content_setting_values.geolocation": 2,
        "profile.default_content_setting_values.notifications": 2
    })

executable_path = r'chromedriver'
os.environ["webdriver.chrome.driver"] = executable_path


global driver



driver = webdriver.Chrome(r'chromedriver', options=opt)
time.sleep(5)

driver.get("https://login.yahoo.com/account/create")

# Fname and Lname
time.sleep(6)
driver.find_element_by_xpath("//input[@name='firstName']").send_keys("fname")
time.sleep(3)
driver.find_element_by_xpath("//input[@name='lastName']").send_keys("lname")

# Email
time.sleep(3)
numberid = random.randint(100000, 900000)
driver.find_element_by_xpath("//input[@name='yid']").send_keys("fname" + str(numberid) + "lname")

# Password
time.sleep(3)
driver.find_element_by_xpath("//input[@name='password']").send_keys("TestEPWD.")

######## number region +
FC = '(+212)'
option_el = driver.find_element_by_xpath("//option[contains(text(),'%s')]" % FC)
option_el.click()

driver.find_element_by_xpath("//input[@name='phone']").send_keys('684838340')

# Choose date
Month = random.randint(1, 12)
Months = "//option[@value='{}']".format(Month)
monthselect = driver.find_element_by_xpath(Months)
monthselect.click()

time.sleep(3)
Day = random.randint(1, 27)
driver.find_element_by_xpath("//input[@name='dd']").send_keys(Day)

time.sleep(3)
Year = random.randint(1975, 2000)
driver.find_element_by_xpath("//input[@name='yyyy']").send_keys(Year)

time.sleep(3)
list = ["Man", "Woman"]
item = random.choice(list)
driver.find_element_by_xpath("//input[@name='freeformGender']").send_keys(item)

time.sleep(3)
driver.find_element_by_xpath("//button[@name='signup']").click()

time.sleep(5)

# CAPTCHA PART :
api_key = os.getenv('APIKEY_2CAPTCHA', 'mycaptchaAPI')

solver = TwoCaptcha(api_key)
yy = driver.current_url

try:
    result = solver.recaptcha(
        sitekey="6LeGXAkbAAAAAAMGHQaxwylqpyvtF2jJMrvJff1h",
        url=yy,
        entreprise=1,
        version='v3',
        score=0.2
        )

except Exception as e:
    print(e)

else:
    print('result: ' + str(result))

标签: pythonseleniumrecaptchacaptchayahoo

解决方案


推荐阅读