Ruby on Rails,如何确定请求是由机器人还是搜索引擎蜘蛛发出的? [英] Ruby on Rails, How to determine if a request was made by a robot or search engine spider?

查看:48
本文介绍了Ruby on Rails,如何确定请求是由机器人还是搜索引擎蜘蛛发出的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Rails 应用程序,它记录每个请求到特定 URL 的 IP 地址,但在我的 IP 数据库中,我发现了 facebook blok IP,如 66.220.15.* 和 Google IP(我建议它来自 bot).是否有任何公式可以确定机器人或搜索引擎蜘蛛发出的请求中的 IP?谢谢

I've Rails apps, that record an IP-address from every request to specific URL, but in my IP database i've found facebook blok IP like 66.220.15.* and Google IP (i suggest it come from bot). Is there any formula to determine an IP from request was made by a robot or search engine spider ? Thanks

推荐答案

机器人需要(比任何法律都更符合常识/礼貌)随用户代理发送他们的请求.您可以使用 request.env["HTTP_USER_AGENT"] 进行检查并根据需要进行过滤.

Robots are required (by common sense / courtesy more than any kind of law) to send along a User-Agent with their request. You can check for this using request.env["HTTP_USER_AGENT"] and filter as you please.

这篇关于Ruby on Rails,如何确定请求是由机器人还是搜索引擎蜘蛛发出的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆