我使用的是pythonSelify来创建一个不一致的帐户(https://discord.com/register),但它是由hcaptcha保护的。我有一个验证码API(2captcha/capmonster)来返回验证码令牌,并将其放入g-captcha-Response文本区域。通常会有一个提交按钮,您可以在之后点击该按钮,然后允许您访问站点(如果验证码是正确的),但一旦您手动完成hcaptcha,Discorde会自动重定向您。我假设Discorde正在使用hcaptcha回调函数。但是我没有找到回调函数,所以我可以在输入captcha令牌后调用它。
以下是我到目前为止拥有的代码:
import random
import requests
import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
email = "example@gmail.com"
username = "exampleusername"
password = "examplepassword"
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://discord.com/register')
WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, "//input[@type='email']")))
driver.find_element_by_xpath("//input[@type='email']").send_keys(email) # email
driver.find_element_by_xpath("//input[@type='text']").send_keys(username) # username
driver.find_element_by_xpath("//input[@type='password']").send_keys(password) # password
driver.find_element_by_xpath('//*[@id="app-mount"]/div[2]/div/div[2]/div/form/div/div[2]/div[4]/div[1]/div[1]/div/div/div/div/div[2]/div').click()
actions = ActionChains(driver)
actions.send_keys(str(random.randint(1, 12))) # Month
actions.send_keys(Keys.ENTER)
actions.send_keys(str(random.randint(1, 28))) # Day
actions.send_keys(Keys.ENTER)
actions.send_keys(str(random.randint(1989, 2000))) # Year
actions.perform()
try:
driver.find_element_by_class_name('inputDefault-3JxKJ2').click() # Agree to terms and conditions
except:
pass
driver.find_element_by_class_name('button-3k0cO7').click() # Submit button
# get captcha key
site_key = 'f5561ba9-8f1e-40ca-9b5b-a0b3f719ef34'
url = "https://discordapp.com/register"
API_KEY = "CAPMONSTER API KEY"
s = requests.Session()
data_post = {
"clientKey": API_KEY,
"task":
{
"type": "HCaptchaTaskProxyless",
"websiteURL": url,
"websiteKey": site_key
}
}
captcha_id = s.post("https://api.capmonster.cloud/createTask", json=data_post).json()
data_get = {
"clientKey": API_KEY,
"taskId": captcha_id['taskId']
}
captcha_answer = s.get("https://api.capmonster.cloud/getTaskResult", json=data_get).json()
while captcha_answer['status'] == "processing":
time.sleep(5)
captcha_answer = s.get("https://api.capmonster.cloud/getTaskResult", json=data_get).json()
captcha_token = captcha_answer["solution"]["gRecaptchaResponse"]
driver.execute_script(f'document.getElementsByName("g-recaptcha-response")[0].innerText="{captcha_token}";') # put captcha token into g-recaptcha-response textarea
driver.execute_script(f'document.getElementsByName("h-captcha-response")[0].innerText="{captcha_token}";')
# code to submit captcha token
1条答案
按热度按时间dxxyhpgq1#
你应该尝试手动求解验证码,看看有什么不同,注意到元素有什么变化吗?
将captcha令牌注入h-captcha-Response&g-reCAPTCHA-Response元素总是会抛出错误。
我会给你一个例子,有时在求解hCaptcha之后会生成一个新的隐藏元素,所以你可以做的就是创建完全相同的元素