Здравствуйте,подскажите пожалуйста как правильно оптимизировать работу бесконечного цикла?После 30 прохождения пишет:captcha verifed failed.Он меня начинает воспринимать как робота ,как "очеловечить" код?Что уже только не делал.Заранее благодарен
import time
import undetected_chromedriver as uc
from fake_useragent import UserAgent
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium_stealth import stealth
from webdriver_manager.chrome import ChromeDriverManager
url = "https://armenia.blsspainvisa.com/book_appointment.php"
while True:
ua = UserAgent()
options = uc.ChromeOptions()
options.add_argument(
"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument("--disable-extensions")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-popup-blocking")
options.add_argument("--profile-directory=Default")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--disable-plugins-discovery")
options.add_argument("--incognito")
options.add_argument("user_agent=DN")
email = 'example@mail.com'
phone_code = '374'
number = '25564564665'
driver = webdriver.Chrome(chrome_options=options,
executable_path=ChromeDriverManager().install()) # Иногда нужно явно указать адрес
# web драйвера executable_path=r"F:\GIT\siteparser\seleniumparse\chromedriver.exe"
stealth(driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
)
driver.delete_all_cookies()
driver.maximize_window()
# if (posts == int(0)):
# print((posts == int(0)))
# driver.get(url=urls[0])
# time.sleep(10)
# pyautogui.write(GMAIL.lower())
# pyautogui.press('tab', presses=3)
# pyautogui.press('enter')
#
# time.sleep(10)
# pyautogui.write(PASSWORD)
# pyautogui.press('enter')
#
# continue
while True:
try:
driver.get(url=url)
city = Select(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "centre"))))
city.select_by_visible_text('Yerevan')
time.sleep(2)
driver.find_element(By.ID,
'app_type1').click()
time.sleep(2)
driver.find_element(By.ID,
'phone_code').clear()
driver.find_element(By.ID,
'phone_code').send_keys(phone_code)
time.sleep(2)
# code = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID,
# 'phone_code')))
#
# code.send_keys(phone_code)
driver.find_element(By.ID,
'phone').send_keys(number)
time.sleep(2)
# phone_number = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID,
# 'phone')))
#
# phone_number.send_keys(number)
driver.find_element(By.ID,
'email').send_keys(email)
time.sleep(2)
# email_user = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID,
# 'email')))
#
# email_user.send_keys(email)
category = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "category"))))
time.sleep(2)
category.select_by_visible_text('Prime Time')
time.sleep(2)
driver.find_element(By.CLASS_NAME,
'close').click()
time.sleep(2)
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, "save")))
actions = ActionChains(driver)
actions.move_to_element(element).perform()
driver.execute_script("arguments[0].click();", element)
time.sleep(4)
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, "agree")))
actions = ActionChains(driver)
actions.move_to_element(element).perform()
driver.execute_script("arguments[0].click();", element)
except:
continue