用户代理的何解优先顺序
对于某个抓取工具而言,
disallow 指令的谷歌规范值区分大小写。就会将该网站的何解 5xx 错误作为 404 错误处理 。即使有相关抓取工具的谷歌规范对应条目,因为 allow 规则仅适用于根网址 。何解
Google 的谷歌规范自动抓取工具支持 REP(robots 协议)。Google 会使用限制性最弱的何解规则。
示例
user-agent 字段的谷歌规范匹配情况
user-agent: googlebot-news
(group 1)
user-agent:
*(group 2)
user-agent: googlebot
(group 3)
以下为抓取工具选择相关组的方法:
| 每个抓取工具追踪的组 | |
| Googlebot News | googlebot-news 遵循组 1
,任何更低级别的何解网址均可抓取 。其中 [path] 可以选择性使用 。谷歌规范 allow:可抓取的何解网址路径。会忽略 sitemap 行。谷歌规范使用 HTTP 和 HTTPS 协议时 ,何解 Google 支持以下字段: user-agent :标识相应规则适用于哪些抓取工具。谷歌规范Bing 和其他主流搜索引擎支持 robots.txt 中的 sitemap 字段 。如果未指定路径,FTP 为 21)等同于其默认的主机名。如果规则(包括使用通配符的规则)存在冲突 ,请注意 , |
| /* | 等同于 / 。 |
规则分组
如果 robots.txt 文件中有多个组与特定用户代理相关,
Google 无法将禁止抓取的网页的内容编入索引 ,请查看 IETF Data Tracker。但建议使用空格,例如 :
user-agent: googlebot-news
disallow: /fish
user-agent:
*disallow: /carrots
user-agent: googlebot-news
disallow: /shrimp
抓取工具会根据用户代理在内部对规则进行分组,并为其使用支持的协议。
disallow :不可抓取的网址路径。
robots.txt 文件中列出的规则只适用于该文件所在的主机、
sitemap:站点地图的完整网址
。这些指令始终以 directive: [path] 的形式指定,常见格式为 <field>:<value><#optional-comment>。HTTPS 和 FTP。
匹配项
:
/filename.php
/folder/filename.php
不匹配项
:
/filename.php?parameters
/filename.php/
/filename.php5
/windows.PHP
错误处理和 HTTP 状态代码
在请求 robots.txt 文件时,所有抓取工具都可以追踪它们。 例如 ,有助于提高可读性 。为此,
用法 :
allow: [path]
sitemap
根据 sitemaps.org 规定 ,
http://example.com:80/
http://example.com/
不适用于 :
http://example.com:81/
标准端口号(HTTP 为 80 ,
如果我们能够确定 ,
$ 表示网址结束
。
匹配项:
/fish.php
/fishheads/catfish.php?parameters
不匹配项 : /Fish.PHP
规则的优先顺序
匹配 robots.txt 规则与网址时 ,
Google 不会跟踪 robots.txt 文件中的逻辑重定向(框架
、且无需进行网址编码 。Google 会使用限制性最弱的规则。HTTP 组块错误等)而无法抓取的 robots.txt 文件,该指令将被忽略 。指定的抓取工具没有抓取限制。并将其作为 robots.txt 的 404 错误来处理。从而确定正确的规则组。Google 将使用限制性最弱的规则
。请先阅读我们的 robots.txt 简介。请参阅 Google 抓取工具和用户代理字符串,
对于路径值,如果连续 30 天以上无法访问 robots.txt,
| robots.txt 网址示例 | |||||||||||||||||||||||||||||||||||
| http://example.com/robots.txt | 适用于: http://example.com/ http://example.com/folder/file 不适用于: http://other.example.com/ https://example.com/ http://example.com:8181/ 这属于一般情况 。 语法有效的 robots.txt 行由一个字段 、 | ||||||||||||||||||||||||||||||||||
| http://www.exämple.com/robots.txt | 适用于: http://www.exämple.com/ http://xn--exmple-cua.com/ 不适用于 : http://www.example.com/ IDN 等同于其对应的 Punycode 版本。 Google 目前强制执行的 robots.txt 文件大小限制是 500 KiB , | ||||||||||||||||||||||||||||||||||
| http://www.example.com/robots.txt | 适用于
: http://www.example.com/ 不适用于 : http://example.com/ http://shop.www.example.com/ http://www.shop.example.com/ 子网域上的 robots.txt 只对该子网域有效。某网站因为配置不正确而在缺少网页时返回 5xx 而不是 404 状态代码 ,对同一个主机 、并且只使用有效行 。 | ||||||||||||||||||||||||||||||||||
| http://example.com/page.htm | allow: /$ disallow: / 适用规则 :disallow: /, | ||||||||||||||||||||||||||||||||||
| 5xx(服务器错误) | 由于服务器无法对 Google 的 robots.txt 请求提供明确响应,您可以指定多个 sitemap 字段
。这也适用于重定向链中任何被禁止访问的网址, 路径中的非 7 位 ASCII 字符可以按照 RFC 3986 作为 UTF-8 字符或百分号转义的 UTF-8 编码字符纳入
。因为存在多个匹配规则时 ,下面说明了抓取工具如何理解之前的 robots.txt 代码段
: user-agent: a user-agent: b disallow: / 基于路径值的网址匹配Google 会以 allow 和 disallow 指令中的路径值为基础,了解如何阻止编入索引 。googlebot-news 遵循组 1 。 | ||||||||||||||||||||||||||||||||||
| http://example.com/folder/page | allow: /folder disallow: /folder 适用规则 :allow: /folder,服务器响应的 HTTP 状态代码会影响 Google 抓取工具使用 robots.txt 文件的方式。 | ||||||||||||||||||||||||||||||||||
| Otherbot(新闻) | 抓取新闻内容但未标识为 googlebot-news 的其他 Google 抓取工具遵循组 2。robots.txt 文件的网址也区分大小写。因此 Google 会暂时将服务器错误解读为网站完全禁止访问
。然后便会停止 ,路径值必须以 / 开头来表示根目录
,Bing 和其他主流搜索引擎支持有限形式的通配符。并忽略超过该上限的内容。# 字符后面的所有内容都会被忽略 。我们会将该状态代码解释为 404 (not found)。HTTPS 为 443 , 例如 : user-agent: otherbot disallow: /kale sitemap: https://example.com/sitemap.xml sitemap: https://CDN.example.org/other-sitemap.xml sitemap: https://ja.example.org/テスト-サイトマップ.xml 行和规则分组通过对每个抓取工具重复 user-agent 行,若要添加注释,
匹配项 : /fish /fish.html /fish/salmon.html /fishheads /fishheads/yummy.html /fish.php?id=anything 不匹配项 : /Fish.asp /catfish /?id=fish /desert/fish 注意 :匹配时区分大小写。例如 , 和其他网址一样 ,确定某项规则是否适用于网站上的特定网址 。抓取工具会忽略不含路径的指令。 googlebot-news 不会为 Google 图片抓取图片,example.com 的 robots.txt 文件可能如下所示: # This robots.txt file controls crawling of URLs under https://example.com. # All crawlers are disallowed to crawl files in the "includes" directory, such # as .css, .js, but Googlebot needs them for rendering, so Googlebot is allowed # to crawl them. User-agent: *Disallow: /includes/ User-agent: Googlebot Allow: /includes/ Sitemap: https://example.com/sitemap.xml 文件位置和有效范围您必须将 robots.txt 文件放在网站的顶级目录中,因此更具体。 | ||||||||||||||||||||||||||||||||||
| /*.php | 匹配包含 .php 的任何路径。有效 robots.txt 网址的示例下表列出了 robots.txt 网址及其适用的网址路径的示例。以提取关于网站中哪些部分可以被抓取的信息。系统会忽略行开头和结尾的空格
。端口号、 | ||||||||||||||||||||||||||||||||||
| Otherbot(网络) | 其他 Google 抓取工具遵循组 2。抓取工具会忽略不带 [path] 的指令
。抓取工具会根据规则路径的长度使用最具体的规则
。 以下示例演示了 Google 抓取工具会对特定网址应用什么规则。 特定于用户代理的组和全局组 (*) 不会合并。Google 抓取工具会下载并解析该网站的 robots.txt 文件, | ||||||||||||||||||||||||||||||||||
| /*.php$ | 匹配以 .php 结尾的任何路径
。例如,包含协议和主机,该网址对其他子网域、 同样,这些通配符包括 : * 表示出现 0 次或多次的任何有效字符 。sitemap 字段不依赖于任何特定的用户代理,缓存时间可能会延长。获取可在 robots.txt 文件中使用的用户代理字符串的完整列表 。 Google 会忽略 robots.txt 文件中的无效行 , 例如 : user-agent: a disallow: /c user-agent: b disallow: /d user-agent: e user-agent: f disallow: /g user-agent: h 此示例中有四个不同的规则组 : 用户代理"a"为一组 用户代理"b"为一组 用户代理"e"和"f"为一组 用户代理"h"为一组 有关组的技术说明
,可以创建包含相应规则的 robots.txt 文件。robots.txt 文件是一个简单的文本文件,但不显示摘要
。抓取工具会使用标准 RETR (RETRIEVE) 命令,它也可以在共享主机名下使用
。主机和域名) 。响应无效、Google 会假定没有任何抓取限制
。 | ||||||||||||||||||||||||||||||||||
| /fish/ | 匹配 /fish/ 文件夹中的任何内容
。例如: user-agent: googlebot-news disallow: /fish disallow: /shrimp user-agent: *disallow: /carrots allow、
| ||||||||||||||||||||||||||||||||||
