AI 爬虫 robots.txt 检查工具:你的站是不是把 AI 挡在门外了
做 GEO(生成式引擎优化),很多人内容做得不错,结构化数据也加了,但 AI 就是不引用。排查到最后,经常卡在一个意想不到的地方:robots.txt 里把 AI 爬虫禁了。
不少网站在早期统一给爬虫加了一刀切的 Disallow: /,或者只放行了 Googlebot、Bingbot 这些搜索爬虫,没管后来才出现的 GPTBot、ClaudeBot、PerplexityBot。结果搜索正常,AI 一个都进不来。这篇写一个工具,把各大 AI 爬虫的访问权限一次查清楚。
各大爬虫的官方说明可以参考:Google 爬虫总览(含 Google-Extended)、OpenAI 爬虫说明、Common Crawl。
工具能检查什么
- 下载并解析
robots.txt - 逐个判断主流 AI 爬虫是被允许、禁止,还是部分禁止
- 列出
robots.txt里声明的 sitemap - 给出 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 是开着门还是锁着门。觉得有用欢迎点赞、收藏、转发,有疑问评论区留言或私信交流。