浏览 3788 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-04-09
我的做法是: 在ApplicationController中加上如下代码: before_filter :init def init init_bot ... end def init_bot blocked_bots = ["qihoo.net"...] blocked_bots.each do |bot| if request.env["HTTP_USER_AGENT"] and request.env["HTTP_USER_AGENT"].downcase.include?(bot.downcase) render :text => "" return end end end 这样的处理方法对于别的一些爬虫没有问题,但是遇到qihoo却会出错,搞得邮箱中一大堆错误报告: A ActionController::DoubleRenderError occurred in ...: Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". /usr/local/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1136:in `redirect_to_full_url' ... * HTTP_USER_AGENT : Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; CollapsarWEB qihoobot@qihoo.net) ... 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2010-04-09
直接在web server上面封就好了,没必要用rails写程序处理。
|
|
返回顶楼 | |
发表时间:2010-04-10
系统程序 写道 对于流氓,最好的处理方法是封杀之。
我的做法是: 在ApplicationController中加上如下代码: before_filter :init def init init_bot ... end def init_bot blocked_bots = ["qihoo.net"...] blocked_bots.each do |bot| if request.env["HTTP_USER_AGENT"] and request.env["HTTP_USER_AGENT"].downcase.include?(bot.downcase) render :text => "" return end end end 这样的处理方法对于别的一些爬虫没有问题,但是遇到qihoo却会出错,搞得邮箱中一大堆错误报告: A ActionController::DoubleRenderError occurred in ...: Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". /usr/local/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1136:in `redirect_to_full_url' ... * HTTP_USER_AGENT : Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; CollapsarWEB qihoobot@qihoo.net) ... return只是跳出这个方法,换用exit就可以了 |
|
返回顶楼 | |
发表时间:2010-04-13
错误在于你的代码本身。既然 init_bot 是个 before_filter 那就应该 return false
|
|
返回顶楼 | |
发表时间:2010-04-13
nginx:
if ($http_user_agent ~* "qihoobot") { return 403; } |
|
返回顶楼 | |