format - Robots.txt - 多个用户代理的抓取延迟的正确格式是什么?

标签 format web-crawler robots.txt agents

下面是一个示例 robots.txt 文件,用于允许多个用户代理,每个用户代理具有多个抓取延迟。抓取延迟值仅供说明之用,在真实的 robots.txt 文件中会有所不同。

我在整个网络上搜索了正确的答案,但找不到。有太多混杂的建议,我不知道哪个是正确/正确的方法。

问题:

(1) 每个用户代理可以有自己的抓取延迟吗? (我认为是的)

(2) 将每个用户代理的抓取延迟行放在允许/禁止行之前还是之后?

(3)每个用户代理组之间是否必须有一个空格。

引用文献:

http://www.seopt.com/2013/01/robots-text-file/

http://help.yandex.com/webmaster/?id=1113851#1113858

本质上,我希望使用下面示例中的值来了解最终的 robots.txt 文件应该是什么样子。

提前致谢。

# Allow only major search spiders    
User-agent: Mediapartners-Google
Disallow:
Crawl-delay: 11

User-agent: Googlebot
Disallow:
Crawl-delay: 12

User-agent: Adsbot-Google
Disallow:
Crawl-delay: 13

User-agent: Googlebot-Image
Disallow:
Crawl-delay: 14

User-agent: Googlebot-Mobile
Disallow:
Crawl-delay: 15

User-agent: MSNBot
Disallow:
Crawl-delay: 16

User-agent: bingbot
Disallow:
Crawl-delay: 17

User-agent: Slurp
Disallow:
Crawl-delay: 18

User-agent: Yahoo! Slurp
Disallow:
Crawl-delay: 19

# Block all other spiders
User-agent: *
Disallow: /

# Block Directories for all spiders
User-agent: *
Disallow: /ads/
Disallow: /cgi-bin/
Disallow: /scripts/

(4) 如果我想将所有用户代理的抓取延迟设置为 10 秒,以下内容是否正确?

# Allow only major search spiders
User-agent: *
Crawl-delay: 10

User-agent: Mediapartners-Google
Disallow:

User-agent: Googlebot
Disallow:

User-agent: Adsbot-Google
Disallow:

User-agent: Googlebot-Image
Disallow:

User-agent: Googlebot-Mobile
Disallow:

User-agent: MSNBot
Disallow:

User-agent: bingbot
Disallow:

User-agent: Slurp
Disallow:

User-agent: Yahoo! Slurp
Disallow:

# Block all other spiders
User-agent: *
Disallow: /

# Block Directories for all spiders
User-agent: *
Disallow: /ads/
Disallow: /cgi-bin/
Disallow: /scripts/

最佳答案

(1) Can each user agent have it's own crawl-delay?

是的。每个记录,由一个或多个 User-agent 开始线,可以有Crawl-delay线。请注意Crawl-delay不属于 original robots.txt specification 。但对于那些理解它的解析器来说,包含它们是没有问题的,如规范 defines 所示。 :

Unrecognised headers are ignored.

因此较旧的 robots.txt 解析器将简单地忽略您的 Crawl-delay行。

<小时/>

(2) Where do you put the crawl-delay line for each user agent, before or after the Allow / Dissallow line?

没关系。

<小时/>

(3) Does there have to be a blank like between each user agent group.

是的。 记录必须用一行或多行换行分隔。请参阅original spec :

The file consists of one or more records separated by one or more blank lines (terminated by CR,CR/NL, or NL).

<小时/>

(4) If I want to set all of the user agents to have crawl delay of 10 seconds, would the following be correct?

没有。机器人会查找与其用户代理匹配的记录。只有当他们没有找到记录时,他们才会使用 User-agent: *记录。因此,在您的示例中,所有列出的机器人(如 GooglebotMSNBotYahoo! Slurp 等)将有 no Crawl-delay .

<小时/>

另请注意,您不能拥有 several records with User-agent: * :

If the value is '*', the record describes the default access policy for any robot that has not matched any of the other records. It is not allowed to have multiple such records in the "/robots.txt" file.

因此解析器可能会查找(如果没有其他记录匹配)第一个记录 User-agent: *并忽略以下内容。对于第一个示例,这意味着以 /ads/ 开头的 URL , /cgi-bin//scripts/ 没有被阻止。

即使您只有一条记录 User-agent: * ,那些Disallow线路仅适用于没有其他记录匹配的机器人!正如您的评论 # Block Directories for all spiders建议,您希望所有蜘蛛都阻止这些 URL 路径,因此您必须重复 Disallow 每条记录的行。

关于format - Robots.txt - 多个用户代理的抓取延迟的正确格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17377835/

相关文章:

seo - robots.txt 错误 : Content Type should be text/plain

Python:字符串中用户定义的数字格式

ruby - Rails 应用程序的出生日期正则表达式 yyyy-mm-dd

html - VBA Excel点击 "submit"后提取新的网页数据

python - 如何重用Spider上的yield

user-agent - robots.txt 中指令的顺序,它们是相互覆盖还是相互补充?

seo - X-Robots-Tag HTTP header 与 robots.txt 的优先级

Javascript 与 jquery datepicker 使用 knockout

c# - Linq 刚刚开始

javascript - 如何在 PhantomJS 中跟踪 document.location.reload?