AI 爬蟲實際從你的網站拿到什麼?一支 66 行的指令碼告訴你
分別以瀏覽器和各個 AI 爬蟲的身分請求你的網頁,再比較結果。如果只有爬蟲收到 403、429 或驗證頁面,或是回應雖為 200 但比瀏覽器看到的頁面小很多,就表示即使 robots.txt 允許,防火牆仍然拒絕了它。這支 66 行的 Node 指令碼會對七個爬蟲執行檢查,並依 RFC 9309 規則讀取 robots.txt。
robots.txt 只告訴爬蟲可以抓取什麼,卻不會說明防火牆或 CDN 實際回傳了什麼。本文提供一支簡短的指令碼,把兩者並排顯示,讓你看出它們在哪裡不一致。
為什麼 robots.txt 無法告訴你爬蟲拿到什麼?
robots.txt 只是一種請求。真正回傳什麼內容,是由防火牆、CDN 或機器人防護規則決定的。它們可能對 OAI-SearchBot 或 PerplexityBot 回傳 403、429 或「Just a moment...」頁面,而你用自己的瀏覽器造訪時卻一切正常。
檢查方法是分別以瀏覽器和爬蟲的身分請求同一個網址,然後比較結果。只有爬蟲收到 403、429 或 503、頁面標題是 Just a moment...,或是回應為 200 但比瀏覽器的小很多,這些都指向防火牆。
指令碼
將它存成 ai-crawler-view.mjs。它需要 Node 18 或更新版本,不需要安裝任何套件。它會先讀取一次 robots.txt,接著以瀏覽器身分抓取你的網頁,再以七個 AI 爬蟲的身分抓取:OAI-SearchBot、ChatGPT-User、GPTBot、Claude-SearchBot、ClaudeBot、PerplexityBot 和 Perplexity-User。
#!/usr/bin/env node
// ai-crawler-view: what do AI crawlers get from YOUR site, compared with a browser?
// Usage: node ai-crawler-view.mjs https://your-site.com/page [--expect "a sentence from your page"]
// Node 18+, no dependencies. Run it against sites you own: it sends requests with crawler user agents.
const BROWSER = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
const BOTS = [ // [robots.txt token, user agent]; Anthropic prints no full strings, so Claude gets a token-based one
["OAI-SearchBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; OAI-SearchBot/1.0; +https://openai.com/searchbot"],
["ChatGPT-User", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0; +https://openai.com/bot"],
["GPTBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; GPTBot/1.1; +https://openai.com/gptbot"],
["Claude-SearchBot", "Mozilla/5.0 (compatible; Claude-SearchBot/1.0)"],
["ClaudeBot", "Mozilla/5.0 (compatible; ClaudeBot/1.0)"],
["PerplexityBot", "Mozilla/5.0 (compatible; PerplexityBot/1.0; +https://perplexity.ai/perplexitybot)"],
["Perplexity-User", "Mozilla/5.0 (compatible; Perplexity-User/1.0; +https://perplexity.ai/perplexity-user)"],
];
const BLOCK = new Set([401, 403, 406, 429, 451, 503, 999]);
const CHALLENGE = /Just a moment\.\.\.|Attention Required! \| Cloudflare|\/cdn-cgi\/challenge-platform|_Incapsula_Resource|Access Denied/i;
const [url, ...rest] = process.argv.slice(2);
const expect = rest.includes("--expect") ? rest[rest.indexOf("--expect") + 1] : "";
if (!url) { console.error("usage: node ai-crawler-view.mjs https://site/page [--expect \"text\"]"); process.exit(2); }
async function get(u, ua) {
try {
const r = await fetch(u, { headers: { "user-agent": ua }, redirect: "follow", signal: AbortSignal.timeout(15000) });
return { status: r.status, body: (await r.text()).slice(0, 500000) };
} catch (e) { return { status: 0, body: "", error: e.cause?.code || e.name }; }
}
// robots.txt, RFC 9309 in short: the group naming the token wins, else "*"; longest match wins; Allow wins a tie.
function robotsVerdict(txt, token, path) {
const groups = []; let cur = null;
for (const raw of txt.split(/\r?\n/)) {
const m = raw.replace(/#.*/, "").match(/^\s*([A-Za-z-]+)\s*:\s*(.*?)\s*$/); if (!m) continue;
const [k, v] = [m[1].toLowerCase(), m[2]];
if (k === "user-agent") { if (!cur || cur.rules.length) groups.push(cur = { agents: [], rules: [] }); cur.agents.push(v.toLowerCase()); }
else if (cur && (k === "allow" || k === "disallow") && v) cur.rules.push([k, v]);
}
const g = groups.find(x => x.agents.includes(token.toLowerCase())) || groups.find(x => x.agents.includes("*"));
if (!g) return "no rule";
let best = null;
for (const [k, p] of g.rules) {
const re = new RegExp("^" + p.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\\\$$/, "$"));
if (re.test(path) && (!best || p.length > best[1].length || (p.length === best[1].length && k === "allow"))) best = [k, p];
}
return best ? `${best[0]}: ${best[1]}` : "no rule";
}
const target = new URL(url);
const robots = await get(new URL("/robots.txt", target).href, BROWSER);
const robotsOk = robots.status >= 200 && robots.status < 300 && !/<html/i.test(robots.body);
const control = await get(url, BROWSER);
const cLen = control.body.length;
console.log(`control (browser): HTTP ${control.status}, ${cLen} bytes${expect ? `, expected text ${control.body.includes(expect) ? "found" : "MISSING"}` : ""}`);
if (control.status === 0 || BLOCK.has(control.status)) console.log(" the browser request itself failed or was refused: results below are not meaningful");
console.log(`robots.txt: ${robots.status >= 500 ? "server error (RFC 9309: crawlers must assume everything is disallowed)" : robotsOk ? "read" : "none or not valid"}\n`);
console.log("crawler robots.txt HTTP bytes verdict");
for (const [token, ua] of BOTS) {
const r = await get(url, ua);
const rule = robotsOk ? robotsVerdict(robots.body, token, target.pathname + target.search) : "no rule";
const challenge = CHALLENGE.test(r.body.slice(0, 20000)) && r.body.length < 20000;
const verdict = BLOCK.has(r.status) || challenge ? "BLOCKED by the server"
: r.status >= 400 || r.status === 0 ? `error ${r.status || r.error}`
: r.body.length < cLen * 0.5 ? "THIN: much smaller than the browser's page"
: expect && !r.body.includes(expect) ? "text MISSING from the HTML" : "ok";
console.log(`${token.padEnd(17)} ${rule.padEnd(19)} ${String(r.status).padEnd(5)} ${String(r.body.length).padEnd(7)} ${verdict}${rule.startsWith("disallow") ? " (robots.txt asks it to stay away)" : ""}`);
} Anthropic 並未公布完整的 user agent 字串,因此兩個 Claude 的項目只使用爬蟲代碼。依代碼比對的防火牆會做出相同的反應。
如何執行?
請對你自己網站的某個頁面執行。選用的 --expect 參數會檢查,主要內容中的某句話是否出現在各個爬蟲收到的原始 HTML 裡。如果沒有出現,表示文字是由指令碼在載入後才加入的,許多爬蟲看不到這些內容。
node ai-crawler-view.mjs https://your-site.com/pricing/ --expect "a sentence from your page" 請只在你擁有或獲准測試的網站上執行。它會發出九個請求:robots.txt、瀏覽器,以及每個爬蟲各一個。
輸出看起來是什麼樣子?
以下是對一台刻意設成不友善的本機測試伺服器執行的結果:它對 OAI-SearchBot 回傳驗證頁面、對 ClaudeBot 限制請求頻率、對 PerplexityBot 回傳空殼頁面,並在 robots.txt 中禁止 GPTBot:
control (browser): HTTP 200, 2618 bytes, expected text found
robots.txt: read
crawler robots.txt HTTP bytes verdict
OAI-SearchBot allow: / 403 31 BLOCKED by the server
ChatGPT-User allow: / 200 2618 ok
GPTBot disallow: / 200 2618 ok (robots.txt asks it to stay away)
Claude-SearchBot allow: / 200 2618 ok
ClaudeBot allow: / 429 9 BLOCKED by the server
PerplexityBot allow: / 200 36 THIN: much smaller than the browser's page
Perplexity-User allow: / 200 2618 ok 在 aiseewhy.com 上,每個爬蟲都拿到完整的頁面,狀態碼與大小都和瀏覽器相同。
如何解讀這張表?
- robots.txt 欄位是你給出的許可:依 RFC 9309,套用到該爬蟲的規則是指名該爬蟲的群組,沒有的話就用
*,再取最長的相符規則,若長度相同則以Allow為準。 - HTTP 和 bytes 欄位是伺服器實際的作為。
GPTBot顯示 200,是因為伺服器會回應任何無視 robots.txt 的請求;旁邊的規則才是守規矩的爬蟲會遵守的。 - 危險的是相反的情況:
allow: /旁邊出現BLOCKED或THIN。這代表網站嘴上說可以,實際上卻拒絕。
指令碼無法告訴你什麼?
- 它是從你自己的 IP 位址測試不同的 user agent,而不是真正的爬蟲。許多防火牆會依據廠商公布的 IP 範圍來驗證爬蟲,因此真正的
OAI-SearchBot可能被放行,而你的請求卻被拒絕,也可能正好相反。請用它找出會依 user agent 反應的規則,再對照各廠商公布的 IP 清單。 - 它刻意不執行 JavaScript:它呈現的是不會渲染頁面的爬蟲所看到的 HTML。
- 結果一切正常並不代表推薦。能被讀取,不等於會被引用。
真實網站的狀況如何?
AISeeWhy 對 14 個爬蟲執行這類檢查。在我們能夠測試的美國、英國和法國 165 個企業網站中,有 38%(63 個網站)在伺服器端拒絕了至少一個 AI 爬蟲,而同一個位址的瀏覽器卻能取得頁面。這些網站每一個都至少拒絕了一個訓練或爬取用的機器人,另有 10%(16 個網站)也至少拒絕了一個 AI 搜尋爬蟲,例如 PerplexityBot(11 個網站)或 OAI-SearchBot(5 個)。
這些網站並非隨機樣本,另有 53 個網站因為連一般的瀏覽器請求都被拒絕或沒有回應而無法測試。請把它當作值得在你自己網站上檢查的現象,而不是全面普查。
下一步
本文提到的爬蟲
常見問題
對任何網站執行這支指令碼安全嗎?
請只對你擁有或獲准測試的網站執行。它會以爬蟲的 user agent 發送請求,有些機器人防禦機制會把這視為惡意行為。
robots.txt 明明禁止 GPTBot,為什麼顯示 ok?
robots.txt 是請求,不是鎖。伺服器會回應任何無視它的請求,所以 HTTP 欄位顯示 ok。旁邊的規則則顯示守規矩的爬蟲會遵守什麼。
這支指令碼會執行 JavaScript 嗎?
不會,這是刻意的。它呈現的是不渲染頁面的爬蟲所收到的 HTML。--expect 參數會告訴你主要文字是否已經包含在那份 HTML 裡。
結果一切正常,就代表 ChatGPT 會引用我的頁面嗎?
不會。能存取是必要條件,但不是充分條件。想知道助理是否會提到你的網站,請用買家會問的問題去問它,並記下它引用了哪些網站。
資料來源
- RFC 9309: Robots Exclusion Protocol
- OpenAI: Overview of OpenAI crawlers
- Anthropic: Does Anthropic crawl data from the web, and how can site owners block the crawler?
- Perplexity: Perplexity crawlers
- Cloudflare: Manage AI crawlers (AI Crawl Control)