Ruby on Rails,如何确定请求是由机器人还是搜索引擎蜘蛛发出的?
我有 Rails 应用程序,记录每个请求到特定 URL 的 IP 地址,但在我的 IP 数据库中,我发现了 facebook blok IP,如 66.220.15.* 和 Google IP(我建议它来自机器人)。是否有任何公式可以确定机器人或搜索引擎蜘蛛发出的请求的 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于表现良好的机器人通常至少会在它们发送的 UA 字符串中包含一个引用 URI,因此:
是查看请求是来自机器人还是来自人类用户代理的简单方法。这似乎比尝试与综合列表进行匹配更稳健。
Since the well behaved bots at least typically include a reference URI in the UA string they send, something like:
is an easy way to see if the request is from a bot vs. a human user's agent. This seems to be more robust than trying to match against a comprehensive list.
我认为您可以使用浏览器 gem 来检查机器人。
https://github.com/fnando/browser
I think you can use browser gem for check bots.
https://github.com/fnando/browser
机器人需要(根据常识/礼貌,而不是任何法律)发送用户代理及其请求。您可以使用
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.另一种方法是使用 crawler_detect gem:
如果您想检测大量不同的机器人(超过 1000 个)。
Another way is to use crawler_detect gem:
It can be useful if you want to detect a large various of different bots (more than 1000).