使用Selenium登录Zalando被检测拦截的问题及解决
解决Zalando(Akamai防护)的Selenium登录检测问题
问题背景
尝试用Selenium自动化登录Zalando时,即使配置了常规的WebDriver防检测参数,依然被Akamai防护拦截,点击登录按钮弹出错误提示:"An error has occurred. Do we start again later?"。试过修改navigator.webdriver标识、初始代理(无效)等方案,最终通过正确配置代理解决问题。
问题重现代码
from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) options.add_argument("--disable-blink-features") options.add_argument("--disable-blink-features=AutomationControlled") driver = webdriver.Chrome(options=options, executable_path=r'path\to\chromedriver.exe') driver.get('https://www.zalando.com')
有效解决步骤
1. 配置合规的代理(核心解决点)
Akamai对IP的真实性、行为特征校验严格,免费/动态数据中心代理极易被识别。需使用高匿名静态住宅代理,确保代理IP与账号常用登录地区匹配,避免频繁切换IP。
代理配置示例:
from selenium import webdriver options = webdriver.ChromeOptions() # 保留原有防检测参数 options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) options.add_argument("--disable-blink-features=AutomationControlled") # 添加代理(替换为你的住宅代理地址) options.add_argument('--proxy-server=http://valid-residential-proxy:port') # 若代理需要账号密码认证,可通过Chrome扩展或第三方库处理 driver = webdriver.Chrome(options=options) driver.get('https://www.zalando.com')
2. 强化WebDriver痕迹隐藏
在原有参数基础上,执行JavaScript进一步伪装浏览器环境:
# 页面加载后执行 driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") # 补充伪装其他浏览器特征 driver.execute_script(""" navigator.__proto__.plugins = new Array(5).fill(null); navigator.__proto__.languages = ['en-US', 'en']; navigator.__proto__.platform = 'Win32'; """)
3. 模拟真实用户操作节奏
避免机械性快速操作,添加随机延迟模拟人类行为:
import time import random from selenium.webdriver.common.by import By # 等待页面加载后随机延迟1-3秒再点击登录 time.sleep(random.uniform(1, 3)) login_button = driver.find_element(By.CSS_SELECTOR, 'your-login-button-selector') login_button.click() # 输入账号时逐字符添加小延迟 username_field = driver.find_element(By.ID, 'login.email') for char in 'your-account-email': username_field.send_keys(char) time.sleep(random.uniform(0.1, 0.3)) # 密码输入同理 password_field = driver.find_element(By.ID, 'login.password') for char in 'your-password': password_field.send_keys(char) time.sleep(random.uniform(0.1, 0.2))
最终解决结论
最初使用的代理不符合Akamai的IP合规要求,更换为有效住宅代理后,配合基础防检测参数与模拟操作,成功绕过拦截完成登录。
内容的提问来源于stack exchange,提问作者Arthur_S
相关产品推荐
相关产品推荐

