You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Selenium向目标输入框传值?(已被Selenium检测)

解决Selenium被youtubemultidownloader.net检测的方案

以下是几种针对性的解决思路,亲测对该网站的反爬检测有效:

  • 使用undetected-chromedriver替代原生Selenium
    这个第三方库专门针对Selenium的反爬检测做了深度优化,会自动处理navigator.webdriver标记、浏览器窗口特征等常见指纹,无需手动配置大量参数。示例代码:

    import undetected_chromedriver as uc
    from selenium.webdriver.common.by import By
    
    # 初始化浏览器
    driver = uc.Chrome()
    driver.get("https://youtubemultidownloader.net/playlists.html")
    
    # 定位输入框并发送内容
    input_box = driver.find_element(By.ID, "inputPlaylist")
    input_box.send_keys("你的播放列表链接")
    
  • 增强原生Selenium的指纹伪装
    如果不想引入第三方库,可以通过组合更多浏览器参数+JS脚本强化伪装,覆盖更多检测点:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    import time
    
    options = Options()
    # 禁用自动化控制标记
    options.add_argument("--disable-blink-features=AutomationControlled")
    # 移除Chrome的自动化提示条
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    # 模拟真实Chrome用户代理
    options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36")
    # 启动最大化窗口,避免窗口尺寸异常被检测
    options.add_argument("--start-maximized")
    # 禁用自动填充,模拟普通用户状态
    options.add_argument("--disable-autofill")
    
    driver = webdriver.Chrome(options=options)
    # 执行JS覆盖navigator.webdriver属性
    driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
    # 额外覆盖其他可能的检测属性
    driver.execute_script("""
        Object.defineProperty(navigator, 'plugins', {get: () => [1,2,3,4,5]});
        Object.defineProperty(navigator, 'languages', {get: () => ['zh-CN', 'zh']});
    """)
    
    driver.get("https://youtubemultidownloader.net/playlists.html")
    # 模拟用户打开页面后的等待时间
    time.sleep(2)
    
    input_box = driver.find_element(By.ID, "inputPlaylist")
    input_box.send_keys("你的播放列表链接")
    
  • 模拟真实用户交互逻辑
    网站可能会通过交互行为的机械性检测Selenium,建议加入更贴近真实用户的操作:

    from selenium.webdriver.common.action_chains import ActionChains
    
    # 定位输入框后
    action = ActionChains(driver)
    # 模拟鼠标移动到输入框并点击
    action.move_to_element(input_box).click().perform()
    # 逐个字符输入,模拟真实打字速度
    playlist_url = "你的播放列表链接"
    for char in playlist_url:
        input_box.send_keys(char)
        time.sleep(0.1)
    
  • 拦截网站的检测脚本
    部分网站会加载第三方检测脚本,可以通过Chrome DevTools协议拦截这些请求:

    # 在driver初始化后、访问页面前添加
    driver.execute_cdp_cmd('Network.setBlockedURLs', {
        "urls": ["*analytics*", "*tracking*", "*detect*"]  # 根据网站实际加载的脚本调整
    })
    driver.execute_cdp_cmd('Network.enable', {})
    

内容的提问来源于stack exchange,提问作者Othman Alkhatib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 14:15:42