关于爬虫:block-yandex-bot

9次阅读

共计 1140 个字符,预计需要花费 3 分钟才能阅读完成。

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,再做决定。

正文完
 0