AI 爬虫 robots.txt 检查工具:你的站是不是把 AI 挡在门外了

AI 爬虫 robots.txt 检查工具:你的站是不是把 AI 挡在门外了

做 GEO(生成式引擎优化),很多人内容做得不错,结构化数据也加了,但 AI 就是不引用。排查到最后,经常卡在一个意想不到的地方:robots.txt 里把 AI 爬虫禁了。

不少网站在早期统一给爬虫加了一刀切的 Disallow: /,或者只放行了 Googlebot、Bingbot 这些搜索爬虫,没管后来才出现的 GPTBot、ClaudeBot、PerplexityBot。结果搜索正常,AI 一个都进不来。这篇写一个工具,把各大 AI 爬虫的访问权限一次查清楚。

各大爬虫的官方说明可以参考:Google 爬虫总览(含 Google-Extended)、OpenAI 爬虫说明、Common Crawl。

工具能检查什么

  1. 下载并解析 robots.txt
  2. 逐个判断主流 AI 爬虫是被允许、禁止,还是部分禁止
  3. 列出 robots.txt 里声明的 sitemap
  4. 给出 GEO 相关的提示

依赖:requests。

完整代码

python 复制代码
# -*- coding: utf-8 -*-
"""
AI 爬虫 robots.txt 检查工具
用途:检查各大 AI 爬虫是否被 robots.txt 允许/禁止,定位 GEO 失效原因
依赖:pip install requests
"""

import requests

HEADERS = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
                  "(KHTML, like Gecko) Chrome/120.0 Safari/537.36",
}

# (user-agent 名称, 说明)
AI_BOTS = [
    ("GPTBot", "OpenAI 抓取训练/回答数据"),
    ("OAI-SearchBot", "OpenAI 搜索引用"),
    ("ChatGPT-User", "ChatGPT 浏览器/插件"),
    ("ClaudeBot", "Anthropic Claude 抓取"),
    ("Claude-Web", "Claude 网页浏览"),
    ("PerplexityBot", "Perplexity 抓取"),
    ("Perplexity-User", "Perplexity 浏览"),
    ("Google-Extended", "Google 训练 Gemini(不影响搜索收录)"),
    ("CCBot", "Common Crawl(训练数据源)"),
    ("Applebot-Extended", "Apple 训练数据"),
    ("Bytespider", "字节跳动"),
    ("anthropic-ai", "Anthropic 早期标识"),
]


def fetch_robots(domain):
    url = domain.rstrip("/") + "/robots.txt"
    try:
        resp = requests.get(url, headers=HEADERS, timeout=10)
        return resp.status_code, resp.text
    except requests.RequestException as e:
        return None, str(e)


def parse_robots(text):
    groups = []
    sitemaps = []
    current = None
    for raw in text.splitlines():
        line = raw.split("#", 1)[0].strip()
        if not line:
            continue
        if ":" not in line:
            continue
        key, _, value = line.partition(":")
        key = key.strip().lower()
        value = value.strip()
        if key == "user-agent":
            if current is not None and not current["rules"]:
                current["agents"].append(value)
            else:
                current = {"agents": [value], "rules": []}
                groups.append(current)
        elif key in ("allow", "disallow"):
            if current is not None:
                current["rules"].append((key, value))
        elif key == "sitemap":
            sitemaps.append(value)
    return groups, sitemaps


def group_for(agent, groups):
    # 精确匹配优先
    for g in groups:
        if agent.lower() in [a.lower() for a in g["agents"]]:
            return g
    # 通配 *
    for g in groups:
        if "*" in g["agents"]:
            return g
    return None


def verdict(g):
    if g is None:
        return "无规则(默认允许)"
    disallow_all = any(k == "disallow" and v == "/" for k, v in g["rules"])
    if disallow_all:
        return "全站禁止"
    if not g["rules"]:
        return "允许"
    disallow_paths = [v for k, v in g["rules"] if k == "disallow"]
    if disallow_paths:
        return f"部分禁止({len(disallow_paths)} 条 Disallow)"
    return "允许(含 Allow 规则)"


def check(domain):
    print(f"检查: {domain}\n" + "=" * 60)
    code, text = fetch_robots(domain)
    if code != 200:
        print(f"robots.txt 无法访问 (HTTP {code})")
        return

    groups, sitemaps = parse_robots(text)
    print(f"解析到 {len(groups)} 个规则组,{len(sitemaps)} 个 sitemap 声明\n")

    for agent, desc in AI_BOTS:
        v = verdict(group_for(agent, groups))
        print(f"{agent:20s} {v:24s} {desc}")

    print("\nSitemap 声明:")
    for s in sitemaps:
        print("  ", s)
    if not sitemaps:
        print("  (未在 robots.txt 声明 sitemap)")

    print("\n提示:")
    print("  - 若 AI 爬虫被 Disallow: /,你的内容不会被对应 AI 抓取,GEO 白做。")
    print("  - Google-Extended 只影响 Gemini 训练,不影响普通搜索收录。")
    print("  - 想只禁止训练、保留 AI 搜索引用,可用更细的路径规则区分。")

    print("\n" + "=" * 60)
    print("检查结束。")


if __name__ == "__main__":
    check("https://example.com")

怎么用

bash 复制代码
pip install requests

把最后一行 check(...) 里的域名换成你自己的,运行。输出里每一行是一个 AI 爬虫的权限结论。

三个值得注意的点

一刀切的 Disallow: / 会连 AI 一起挡。 很多站当年为了「防采集」,直接全站禁止所有爬虫,只放行 Googlebot。这些 User-agent: * 的规则会作用到所有没单独命名的 AI 爬虫身上。你想做 GEO,先确认这条规则还在不在。

Google-Extended 不影响搜索。 谷歌把「搜索收录」和「AI 训练」分开管了,Googlebot 管搜索,Google-Extended 管 Gemini 训练。禁了 Google-Extended,你的站照常进谷歌搜索,只是不参与谷歌 AI 的训练数据。

允许 AI 抓取 ≠ 允许乱抓。 你可以用路径规则精确控制,比如允许 AI 读公开的产品页和文章,禁止它读 /api、/内部 这些后台路径。工具里的「部分禁止」就是这种情况。

写在最后

GEO 的第一道门在 robots.txt,门不开,后面全白费。先把这层查清楚,再谈内容优化。代码拿去用,跑一遍就知道自己站对 AI 是开着门还是锁着门。觉得有用欢迎点赞、收藏、转发,有疑问评论区留言或私信交流。

相关推荐
涛思数据(TDengine)2 小时前
TDengine TSDB 3.4.3.3 上线:流计算分层闭环、虚拟表跨层引用,查询关联一次写完
数据库·人工智能·数据分析·时序数据库·tdengine·工业
木圭的AI时代指南2 小时前
实测 MiniMax M3.1 Flash:同一道 Three.js 大题,两个 agent 差出 4.6 倍
开发语言·javascript·ecmascript
星恒讯工业路由器2 小时前
工业路由器在中小 IoT 场景的选型与适配实践:从标准品到定制化的技术路径
开发语言·网络·物联网·php·工业路由器选型·工业网关odm·链路冗余切换
碧海银沙音频科技研究院2 小时前
基于ATS308X的无线语音交互对话功能实现
人工智能·嵌入式硬件·深度学习·算法
博.闻广见2 小时前
第10篇:Agent系统的性能优化 —— 缓存、压缩与动态模型路由
java·人工智能·后端·spring·agent
看我debug2 小时前
Android 运行时分析工作台 (Demo)。统一管理 Frida 脚本、自动注入(修改运行时代码)、收集结构化结果、生成 JSON 报告。
android·python·pip
海雅达手持终端PDA2 小时前
配电台区杆塔巡检老卡死?海雅达Model 4/HDT500实测
人工智能·物联网·集成测试·能源·政务
叶子丶苏2 小时前
提示词工程格式四段式与少样本-VibeCoding入门笔记06
人工智能·笔记
染指11102 小时前
151.Agent-LangGraph-Send发送(Map-Reduce模式)
人工智能·python·langchain·状态模式·agents