如何避免硒阻塞?

问题描述 投票:0回答:1

我正在尝试创建一个脚本来使用 selenium 自动登录到this 站点。但不可避免地,它总是重定向到一个“不可用”的页面。我已经阅读了许多关于 selenium 阻塞的线程,并尝试使用不同的浏览器,但问题仍然存在。我也在尝试使用代理服务器和不同的操作系统。这是我的代码:

from seleniumwire import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from fake_useragent import UserAgent
from selenium.webdriver.firefox.options import Options
import time

options = webdriver.ChromeOptions()
ua = UserAgent()
userAgent = ua.random
print(userAgent)

options.add_argument(f'user-agent={userAgent}')
options.add_argument("--disable-extensions")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)

driver = webdriver.Chrome(executable_path=r'chromedriver', options=options)

driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

driver.get('https://prenotami.esteri.it')

try:

    email = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.ID, "login-email")))
    email.click()
    correo = '[email protected]'
    for c in correo:
        time.sleep(0.1)
        email.send_keys(c)
    password = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.ID, "login-password")))
    password.click()
    clave = 'Dxxxx2023'
    driver.execute_script('window.scrollTo(0, 700)')
    for c in clave:
        time.sleep(0.1)
        password.send_keys(c)
    driver.execute_script('window.scrollTo(0, 700)')
    time.sleep(1)
    boton_avanti = driver.find_element(By.XPATH, "/html/body/main/div/section[1]/form/button")
    boton_avanti.send_keys(Keys.ENTER)



finally:
    time.sleep(5)

input("waiting")
driver.quit()

我什至尝试过使用 uc_chromedriver 和不同的浏览器。 有人有想法吗?

python selenium-webdriver web navigation recaptcha
1个回答
0
投票

检查这个:https://github.com/diprajpatra/selenium-stealth。尝试不同的设置,如果该站点确实具有针对机器人程序的保护,那么这会有所帮助。

对于 chrome 显式:https://github.com/ultrafunkamsterdam/undetected-chromedriver

© www.soinside.com 2019 - 2024. All rights reserved.