✅ 现象说明
这是 百度风控:Selenium自动化特征被识别,触发滑块验证码
浏览器顶部提示:Microsoft Edge 正由自动测试软件控制,这就是自动化标志性特征,百度检测到后弹出安全验证。
方案:去除自动化特征(重点学习,基础反检测)
启动浏览器时添加参数,隐藏 自动化受控提示,降低被识别概率
python
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
# 1. 配置Edge启动参数,隐藏自动化特征
edge_options = Options()
# 关闭自动化提示框
edge_options.add_experimental_option("useAutomationExtension", False)
edge_options.add_experimental_option("excludeSwitches", ["enable-automation"])
web_driver = webdriver.Edge(
service=Service(executable_path=r"D:\Software\edgedriver_win64\msedgedriver.exe"),
options=edge_options
)
# 执行cdp命令,进一步隐藏特征
web_driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
web_driver.get("https://www.baidu.com")
web_driver.maximize_window()
wait = WebDriverWait(web_driver, 10)
textarea = wait.until(EC.element_to_be_clickable((By.ID, "chat-input-textarea")))
textarea.send_keys("自动化测试学习")
time.sleep(2)
web_driver.quit()
⚠️ 注意:只能降低触发概率,不能100%避免,大厂风控持续更新