block yandex bot

block yandex bot

yandex bot 是 Yandex 搜索引擎的爬虫。在 yandex bot user agent 这篇文章中,我总结了所有 yandexbot 的 User-agent,通过那篇文章,我们可以看出有些 Yandexbot 遵守 robots.txt 协议 ,有些不遵守 robots.txt 协议。

我们需要屏蔽 yandexbot(block yandex bot) 可以通过 robots.txt 和 IP 的方式屏蔽,下面分别来讲。

通过 robots.txt 屏蔽 yandexbot

yandex bot user agent 这篇文章中只有遵守 robots.txt 协议的爬虫我们才能通过 robots.txt 协议来屏蔽,如果不遵守我们就没办法通过 robots.txt 协议来屏蔽。

例如,我们需要屏蔽 YandexBot/3.0 这个爬虫,robots.txt 写法如下:

User-agent: YandexBot

Disallow: /

这样就禁止了所有的 YandexBot 抓取我们网站的任何页面,达到了封锁 yandex bot(block yandex bot) 的目的。

如果我们只是想部分页面不被 YandexBot 抓取,我们可以这样写:

User-agent: Yandex

Allow: /

Disallow: /private/user-info

我们允许 YandexBot 访问所有页面,但是最后一条禁止访问 /private/user-info 页面,这样就达到了我们的目的。

还有一些 Yandex bot 并不遵守 robots.txt 协议,所以我们就需要通过 IP 或者 IP 地址段来屏蔽了。

通过 IP 地址来屏蔽 Yandex bot

我们通过 YandexBot 页面可以查询出具体 Yandex bot 的 IP 地址,例如:YandexMobileBot/3.0 并不遵守 robots.txt 协议,所以我们需要通过屏蔽 IP 的方式屏蔽 Yandex bot,通过这个页面显示的 IP ,我们随便选择一个 IP 作为示例:95.108.213.6

如果我们前端服务器(例如:Nginx,Apache)运行的是 Linux 我们可以直接输入以下命令屏蔽 Yandex bot:

sudo iptables -A INPUT -s 95.108.213.6 -j DROP

这样 YandexMobileBot/3.0 就无法抓取我们网站上的内容了。

我们可以一条一条的输入 IP 地址,通过防火墙来屏蔽。

总结

屏蔽 Yandex bot 我们使用了两种方法,一种是:通过 robots.txt 来屏蔽,还有一种是:通过 IP 地址来屏蔽,如果 Yandexbot 不遵守 rotbots.txt 协议,我们就用 IP 地址来屏蔽。

Yandex bot 是 Yandex 搜索引擎的爬虫,如果我们屏蔽了,可能会给我们带来流量上的损失,请大家考虑好是否一定要屏蔽 Yandex Bot,再做决定。