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

使用Selenium访问彭博网站被检测为爬虫 如何解决数据抓取问题

彭博反爬拦截解决方案
  • 屏蔽Selenium原生特征
    原生Selenium启动的浏览器会留下大量可被检测的特征,包括window.navigator.webdriver标识、浏览器启动参数标记、自动化扩展程序等,启动Chrome时添加以下参数即可屏蔽大部分基础特征:
    from selenium.webdriver.chrome.options import Options
    chrome_options = Options()
    # 移除自动化控制标记
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    # 排除自动化开关
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    # 关闭自动化扩展
    chrome_options.add_experimental_option("useAutomationExtension", False)
    # 启动后运行JS修改webdriver属性
    browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
        "source": "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
    })
    
  • 替换为undetected-chromedriver
    该库是针对反爬场景优化的chromedriver分支,自动处理了绝大部分浏览器指纹特征的修改,无需手动配置大量参数,直接替换原生Selenium的驱动即可,示例代码:
    import undetected_chromedriver as uc
    import time
    import random
    
    browser = uc.Chrome()
    browser.implicitly_wait(10)
    
    # 直接访问目标页面,省略多余的搜索跳转步骤
    target_url = 'https://www.bloomberg.com/quote/HSI:IND'
    browser.get(target_url)
    # 使用随机等待代替固定时长,模拟真人行为
    time.sleep(random.uniform(2,5))
    
  • 优化操作行为模拟
    避免使用固定间隔的time.sleep,替换为随机间隔的等待;输入文本时拆分字符逐次输入,每次输入间隔随机毫秒级时间;点击元素时可适当偏移点击坐标,不要每次都精确点击元素中心,进一步降低自动化特征。
  • 调整请求频次与IP策略
    若单个IP频繁触发拦截,可更换为住宅代理IP分发请求,降低同一IP的请求频率,避免被IP维度封禁。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.12 03:15:03