robots.txt文件详解「建议收藏」

robots.txt文件详解「建议收藏」原文地址:robots.txt-禁止爬虫Robots.txt-禁止爬虫robots.txt用于禁止网络爬虫访问网站指定目录。robots.txt的格式采用面向行的语法:空行、注释行(以#打头)、规则行。规则行的格式为:Field:value。常见的规则行:User-Agent、Disallow、Allow行。User-Agent行User-Agent:r

大家好,又见面了,我是你们的朋友全栈君。

原文地址:robots.txt-禁止爬虫

Robots.txt – 禁止爬虫

robots.txt用于禁止网络爬虫访问网站指定目录。robots.txt的格式采用面向行的语法:空行、注释行(以#打头)、规则行。规则行的格式为:Field: value。常见的规则行:User-Agent、Disallow、Allow行。

User-Agent行

User-Agent: robot-name
User-Agent: *

Disallow和Allow行

Disallow: /path
Disallow:           # 空字符串,起通配符效果,全禁止

Allow: /path
Allow:              # 空字符串,起通配符效果,全允许

搜索引擎的User-Agent对应名称

搜索引擎 User-Agent值
Google googlebot
百度 baiduspider
雅虎 slurp
MSN msnbot
Alexa is_archiver

我在Linux上抓包观察到的一些搜索引擎访问记录:

# tcpdump -n -nn -A -l -s1024 'tcp port 80'|grep User-Agent
User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
User-Agent: Googlebot-Image/1.0
User-Agent: Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; 5 subscribers; feed-id=4619555564728728616)
User-Agent: Mozilla/5.0(compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)
User-Agent: Mozilla/5.0 (compatible; YoudaoBot/1.0; http://www.youdao.com/help/webmaster/spider/; )
User-Agent: Mozilla/5.0 (compatible; JikeSpider; +http://shoulu.jike.com/spider.html)

JikeSpider是即刻搜索(人民搜索)。

robots.txt的补充

如果你没有对网站根目录的写入权限(无法建立robots.txt文件),或你想要某个指定的网页不被搜索引擎收录,可以使用元标签阻止爬虫访问:

<meta name="robots" content="noindex">              <!-- 阻止所有爬虫 -->
<meta name="googlerobot" content="noindex">         <!-- 阻止Google收录 -->

robots元标记的默认值为”index,follow”,它的取值可以是(来自Google站长帮助):

noindex

防止网页被编入索引。

nofollow

防止googlebot从此页面中跟踪链接。

noarchive

防止Google显示网页的快照链接。

noimageindex

不被Google图片搜索索引。

现实中的robots.txt

淘宝屏蔽百度

淘宝屏蔽了百度抓取(2008年9月),http://www.taobao.com/robots.txt的内容:

User-agent: Baiduspider
Disallow: /

User-agent: baiduspider
Disallow: /

百度与360的搜索引擎之争

2012年8月,360推出搜索引擎,并与百度发生正面冲突。百度工程师跑出来说360违反robots协议,偷窃百度内容。以百度知道为例,http://zhidao.baidu.com/robots.txt的内容大致是这样:

User-agent: Baiduspider
Disallow: /w?
Allow: /

User-agent: Googlebot
User-agent: MSNBot
User-agent: Baiduspider-image
User-agent: YoudaoBot
User-agent: Sogou web spider
User-agent: Sogou inst spider
User-agent: Sogou spider2
User-agent: Sogou blog
User-agent: Sogou News Spider
User-agent: Sogou Orion spider
User-agent: JikeSpider
User-agent: Sosospider
Allow: /

User-agent: *
Disallow: /

也就是说对360爬虫而言,应该走最后一条规则,也就是禁止抓取百度知道所有内容。但从360搜索看,有百度知道的内容。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/138632.html原文链接:https://javaforall.net

(0)
上一篇 2022年5月6日 下午5:40
下一篇 2022年5月6日 下午6:00


相关推荐

  • 关于n8n中使用ReadWrite Files from Disk节点在加载数据过程中出现Access to the file is not allowed的问题

    关于n8n中使用ReadWrite Files from Disk节点在加载数据过程中出现Access to the file is not allowed的问题

    2026年3月15日
    2
  • getElementById 方法及用法

    getElementById 方法及用法[转]顾明思义,get-Element-By-Id,就是通过ID来设置/返回HTML标签的属性及调用其事件与方法。用这个方法基本上可以控制页面所有标签,条件很简单就是给每个标签分配一个ID号:document.getElementById(“link”).href;document.getElementById(“link”).target;document.getElementById(“i

    2022年7月15日
    18
  • Python——sklearn库的安装

    Python——sklearn库的安装Python——sklearn库的安装做个笔记,时间久了,都忘了sklearn库的标准名字——scikit-learn。所以,不要用pipinstallsklearn应该是pipinstallscikit-learn真被自己蠢哭了。说明:有的低版本的sklearn库没有”accuracy”,版本问题,更新一下包就可以哈。…

    2022年10月18日
    5
  • Windows系统好用的文本编辑器[通俗易懂]

    Windows系统好用的文本编辑器[通俗易懂]文章目录Windows系统好用的文本编辑器建议notepad3notepad++EmEditorsublimetext3vscodeWindows系统好用的文本编辑器win上默认的编辑器中文名叫[记事本],英文是[notepad],功能很弱…不知道为什么有的人说功能强大,明明撤回功能都只能返回一步的。目前win上有很多好用的编辑器,我只是用了几种,推荐顺便分析一下.链接:https://pan.baidu.com/s/1ZTfl6JtU11_1zuBnspoqYQ提取码:kpth通用优

    2022年5月4日
    582
  • 国内外手机号码正则表达式

    国内外手机号码正则表达式附上语言(文化)代码与国家地区对照表:国家/地区语言代码国家/地区语言代码:简体中文(中国) zh-cn 繁体中文(台湾地区) zh-tw 繁体中文(香港) zh-hk 英语(香港) en-hk 英语(美国) en-us 英语(英国) en-gb 英语(全球) en-ww 英语(加拿大) en-ca 英语(澳大利亚) en-au 英语(爱尔兰) en-ie 英语(芬兰) en-f

    2022年6月1日
    41
  • snmp trap日志「建议收藏」

    snmp trap日志「建议收藏」日志类型有三种,file,syslog和snmptrapsnmptrapd.conf文件内容及参数snmptrapd手册:http://www.net-snmp.org/docs/man/snmptrapd.conf.html,http://www.net-snmp.org/wiki/index.php/Snmptrapd中文翻译:《snmptrapd.conf文件内容及参数》,而且详细列出了参数《SnmpTrap的发送和接收演示》IBM开发者网站关于snmptrap引用最.

    2022年8月20日
    26

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号