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文件),或你想要某个指定的网页不被搜索引擎收录,可以使用元标签阻止爬虫访问:

 name="robots" content="noindex">              name="googlerobot" content="noindex">         

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://www.cnblogs.com/lxwphp/p/7730822.html

Robots.txt - 禁止爬虫相关推荐

  1. Robots.txt - 禁止爬虫(转)

    Robots.txt - 禁止爬虫 robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: v ...

  2. robots.txt网站爬虫文件设置

    目录: 什么是robots.txt robots.txt使用误区 robots.txt使用技巧 什么是robots.txt? robots.txt是搜索引擎中访问网站的时候要查看的第一个文件.Robo ...

  3. 通过Robots.txt禁止搜索引擎收录的方法

    什么是robots.txt文件? 搜索引擎通过一种程序robot(又称spider),自动访问互联网上的网页并获取网页信息. 您可以在您的网站中创建一个纯文本文件robots.txt,在这个文件中声明 ...

  4. robots.txt文件详解

    我们知道,搜索引擎都有自己的"搜索机器人"(ROBOTS),并通过这些ROBOTS在网络上沿着网页上的链接(一般是http和src链接)不断抓取资料建立自己的数据库. 对于网站管理 ...

  5. 搜索引擎蜘蛛及网站robots.txt文件详解

    搜索引擎都有自己的"搜索机器人"(ROBOTS),并通过这些ROBOTS在网络上沿着网页上的链接(一般是http和src链接)不断抓取资料建立自己的数据库. 对于网站管理者和内容提 ...

  6. robots.txt 指定 Sitemap 和robots Meta标签

    robots.txt 指定 Sitemap 和robots Meta标签 robots.txt 指定 Sitemap 和robots Meta标签 http://www.mp322.com/robot ...

  7. 【谷歌推网页爬虫新标准,开源robots.txt解析器】

    https://www.toutiao.com/a1638031116246019 [谷歌推网页爬虫新标准,开源robots.txt解析器] 对于接触过网络爬虫的人来说 robots.txt 绝不陌生 ...

  8. 谷歌推网页爬虫新标准,开源robots.txt解析器

    鱼羊 发自 凹非寺  量子位 报道 | 公众号 QbitAI 对于接触过网络爬虫的人来说 robots.txt 绝不陌生,这一存放于网站根目录下的 ASCII 码文件标明了网站中哪些内容是可以抓取的, ...

  9. Linux企业级项目实践之网络爬虫(29)——遵守robots.txt

    Robots协议(也称为爬虫协议.机器人协议等)的全称是"网络爬虫排除标准"(Robots Exclusion Protocol),网站通过Robots协议告诉搜索引擎哪些页面可以 ...

最新文章

  1. π是无理数证明定积分_证明圆周率是无理数很容易?人类花了2000年!
  2. UITabelView使用流程
  3. android网络技术-WebView的用法
  4. Mac 从本地copy项目到服务器
  5. try、catch、finally 和 throw-C#异常处理
  6. Redis-6.2.5 安装 Linux环境(单机)
  7. 去掉838的“消息已发送”的提示
  8. iOS7 - NSURLSession
  9. 图像处理:Canny边缘检测算法原理(一)
  10. python成语接龙代码_#python# 成语接龙(二)
  11. [NEHE Couse] 05.3D Objects
  12. 每日算法系列【LeetCode 829】连续整数求和
  13. 为知笔记使用自建docker服务后,如何迁移原有账号数据
  14. 10-7 spj-查询供应工程 j1 的供应商
  15. android 微信高仿,Android高仿微信聊天界面代码分享
  16. 电磁原理---电磁炉
  17. Vector-常用CAN工具 - CANoe入门到精通_01
  18. 测试工程师转开发希望大吗?
  19. 交流电及整流滤波电路
  20. 利用PYTHON出小学数学题

热门文章

  1. python给手机发通知_【趣味案例】用Python向手机发送通知
  2. 烟台再亮金名片 金牌城市比给烟台几个亿都值
  3. .NET和.COM和.CN域名区别
  4. css实现照片上传的加号框
  5. 迅视财经 近1亿年前的灭绝蜘蛛
  6. iis6 php mysql 一键_一键搞定:php5 环境集成安装包 for IIS6 修正版
  7. 【Android】Bitmap图像色彩模式:黑白、模糊、老照片、胶卷等(92/100)
  8. hp ProBook 4441s 修复记
  9. 机器视觉中Blob分析
  10. A start job is running for Raise network interfaces(ns/5min 3s)linux设置配dhcp后开机自动联网timeout时间长