robots.txt屏蔽AI爬虫实战:GPTBot、ClaudeBot一个都不放过

AI爬虫到底有多疯狂

去年10月我接手一个企业站,查日志发现每天有40万次请求,其中AI爬虫占了28%。GPTBot一个就吃了8万次抓取,ClaudeBot也不甘示弱每天3.5万。问题是这些内容被拿去训练模型,我一分钱没拿到,服务器带宽倒是先扛不住了。

这事儿不是个例。Semrush统计过,2024年全球Top1000网站里,只有24%主动屏蔽了主流AI爬虫。剩下76%要么不知道,要么配置错了。我见过最离谱的robots.txt,写了User-agent: *然后Disallow:后面啥都没跟,等于全站裸奔。

先认清这些AI爬虫的User-agent

搞清楚对手是谁,这事儿就成了一半。我花了三天扒日志,整理出目前主流的AI爬虫:

User-agent 归属 抓取频率 用途
GPTBot OpenAI GPT训练+检索
ClaudeBot Anthropic Claude训练
Claude-Web Anthropic Claude联网搜索
Bytespider 字节跳动 极高 豆包训练
anthropic-ai Anthropic 旧版标识
Google-Extended Google Gemini训练
PerplexityBot Perplexity 检索增强
CCBot Common Crawl 开源数据集
FacebookBot Meta Llama训练
ImagesiftBot Summerceed 图片抓取

注意Google-Extended这个坑货,它不是独立爬虫,是依附在Googlebot上的标识。你光屏蔽Google-Extended没用,得单独写规则。我一开始就栽在这上面,折腾一周才发现。

robots.txt完整配置模板

下面这套是我线上跑了半年的配置,直接抄就行:

# ===== AI训练爬虫:全部封杀 =====
User-agent: GPTBot
Disallow: /

User-agent: ClaudeBot
Disallow: /

User-agent: Claude-Web
Disallow: /

User-agent: Bytespider
Disallow: /

User-agent: Google-Extended
Disallow: /

User-agent: PerplexityBot
Disallow: /

User-agent: CCBot
Disallow: /

User-agent: FacebookBot
Disallow: /

User-agent: anthropic-ai
Disallow: /

# ===== 放行普通搜索引擎 =====
User-agent: *
Allow: /
Disallow: /admin/
Disallow: /api/
Disallow: /*?session_id=

Sitemap: https://www.heezi.cn/sitemap.xml

这套配置的逻辑很清楚:AI训练用的全杀,普通搜索引擎正常放行。你要是觉得Perplexity这种带流量的想留着,把对应那行注释掉就行。我自己的站,Perplexity来的转化率还行,所以留着Claude-Web和PerplexityBot没封。

想留检索流量怎么办

这里有个微妙的选择。OpenAI的SearchGPT、Perplexity这些AI搜索引擎,你封了它们就不收录你,用户搜不到你。但你要是放行,内容又会被拿去训练。

我的做法是分目录放行:

# GPTBot只允许抓博客,其他全封
User-agent: GPTBot
Allow: /blog/
Allow: /news/
Disallow: /

这样博客内容能被AI搜索引用带流量,核心产品页不被白嫖。实测下来,AI搜索来的流量转化率比百度还高12%,值得放行。

服务器层面也要堵

robots.txt是君子协定,大部分大厂会遵守,但小公司和小作坊根本不鸟你。我日志里见过伪装成Chrome的AI爬虫,User-agent是假的。

Nginx层面加一道保险:

# 屏蔽已知AI爬虫IP段
location / {
    if ($http_user_agent ~* "(GPTBot|ClaudeBot|Bytespider|CCBot|FacebookBot)") {
        return 403;
    }
    if ($http_user_agent ~* "Claude-Web") {
        return 403;
    }
    try_files $uri $uri/ /index.php?$args;
}

加了这道之后,我服务器CPU负载从78%掉到41%,带宽费用月降1800块。这ROI比啥优化都直接。

验证配置是否生效

改完别急着收工,用Google的robots.txt测试器跑一遍。或者直接curl模拟:

curl -A "GPTBot" https://www.heezi.cn/blog/test-page
# 返回403就说明生效了

我习惯改完后挂个监控,用Python定时检查:

import requests
import schedule
import time

def check_ai_crawler():
    crawlers = ['GPTBot', 'ClaudeBot', 'Bytespider', 'Google-Extended']
    for ua in crawlers:
        try:
            r = requests.get('https://www.heezi.cn/blog/test',
                           headers={'User-Agent': ua}, timeout=10)
            if r.status_code == 200:
                print(f'[警告] {ua} 仍可访问!状态码:{r.status_code}')
            else:
                print(f'[正常] {ua} 被拦截,状态码:{r.status_code}')
        except Exception as e:
            print(f'[错误] {ua} 检测失败:{e}')

schedule.every(6).hours.do(check_ai_crawler)
while True:
    schedule.run_pending()
    time.sleep(60)

避坑清单

  • 别只封GPTBot:ClaudeBot、Bytespider抓得更狠,字节那台机器一天能来15万次
  • Google-Extended单独写:它跟Googlebot是两套规则,别搞混
  • robots.txt有缓存:Google缓存周期24-48小时,改完别马上测,等两天
  • 日志要定期查:每月扒一次访问日志,新冒出来的AI爬虫及时加进去
  • Sitemap别忘配:放行搜索引擎的同时记得告诉它们内容在哪
  • 403比Disallow更狠:不守规矩的爬虫,Nginx层面直接拦死