1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

railsでcrawler、botのアクセスを制御する

Last updated at Posted at 2013-07-06
is_crawler.rb
# -*- coding: utf-8 -*-
def crawler? ua
  crawler_ua = [
    "crawler",
    "bot",
    "spider",
    "YahooFeedSeeker",
    "Y!J-(?:BSC|BRO|SRD)/",
    "internal +dummy +connection",
    "libwww",
    "HyperEstraier",
    "curl",
    "wget",
    "facebookexternalhit",
    "ia_archiver",
    "Tumblr"
  ]

  crawler_ua.each{ |reg|
    return true if (/#{reg}/i =~ ua) != nil
  }
  return false
end

p crawler?(request.user_agent)
p crawler?("Y!J-BSC/YATS crawler")
p crawler?('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5')
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?