Я пробую автоматизировать вход в систему с помощью селена Python. Существует HCaptcha, которую нужно решить, прежде чем нажать кнопку входа в систему. Я сделал этот код до сих пор: < /p>
def solve_captcha(self):
solved = False
api_key = os.getenv("TWO_CAPTCHA_APIKEY")
solver = TwoCaptcha(api_key)
code = None
try:
print("Solving captcha......")
result = solver.hcaptcha(
sitekey="ced407c5-238b-4144-9b59-4dcd58092d36",
url="https://www.bakecaincontrii.com/u/login/"
)
except Exception as e:
print(e)
else:
solved = True
code = result["code"]
# sys.exit('solved: ' + str(result))
return str(code)
def test(self, url_path):
wait = WebDriverWait(self, 120)
self.get(url_path)
print("Url hit")
print("going to next step......")
time.sleep(3)
# shake the mouse
actions = ActionChains(self)
num_of_shakes = 2
for _ in range(num_of_shakes):
actions.move_by_offset(5, 5)
actions.move_by_offset(-5, -5)
actions.perform()
time.sleep(2)
# checking for the modal
accept_cookie = wait.until(
EC.visibility_of_element_located((By.XPATH, "//button[@class='btn btn-primary w-50 rounded-pill b1']")))
accept_cookie = wait.until(EC.element_to_be_clickable((
By.XPATH, "//button[@class='btn btn-primary w-50 rounded-pill b1']"
)))
accept_cookie.click()
time.sleep(3)
# accept_cookie.click()
# if accept_cookie.is_displayed():
# accept_cookie.click()
print("check email field....")
xpath_email = "//input[@placeholder='Email']"
xpath_e_mail = "//input[@placeholder='E-mail']"
email = wait.until(EC.element_to_be_clickable((By.XPATH, f"{xpath_email}|{xpath_e_mail}")))
print("email field found...")
email.click()
print("email field clicked")
print("sending keys to email fields")
email.send_keys("")
time.sleep(3)
# filling up the password
password = wait.until(EC.element_to_be_clickable((
By.XPATH, "//input[@placeholder='Password']"
)))
time.sleep(2)
password.click()
time.sleep(2)
password.send_keys("")
time.sleep(2)
# cp = wait.until(EC.element_to_be_clickable(
# (By.XPATH, '//*[@id="hcap-script"]/iframe')
# ))
# print("Captcha loaded")
# time.sleep(3)
# cp.click()
# print("Captcha Clicked")
solve_captcha = self.solve_captcha()
print("code", solve_captcha)
print("processing code to element")
code = str(solve_captcha)
print(type(code))
time.sleep(2)
script = f"document.querySelector(" + "'" + '[name="h-captcha-response"]' + "'" + ").innerHTML = " + "'" + code + "'"
# script = f'document.querySelector(\'input[name="h-captcha-response"]\').value = "{code}";'
print(script)
self.execute_script(script)
print("now going to login")
print("login button processing......")
time.sleep(2)
# login
login_button = wait.until(EC.element_to_be_clickable((
By.XPATH, '//*[@id="app"]/main/div[2]/form/button'
)))
login_button.click()
time.sleep(2)
< /code>
Но проблема, которую я получил сейчас, заключается в том, что я не могу отправить Hcaptcha. Как и после решения капты, отметка тика не приближается. Я пытался много искать, но не смог найти решение для этого. Как я могу проверить отметить Hcaptha, когда она решается.>
Подробнее здесь: https://stackoverflow.com/questions/782 ... solving-it
Как я могу отправить hcaptcha после решения ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение