我在我的rails應用程序中安裝了滾動條。它保持報告記錄沒有發現,這是搜索引擎優化(SEO botrawlers)(即谷歌機器人,百度,findxbot等)搜索已刪除的帖子的結果。如何防止rollbar報告搜索引擎優化爬蟲活動?
如何防止rollbar報告SEO scrawler活動。
我在我的rails應用程序中安裝了滾動條。它保持報告記錄沒有發現,這是搜索引擎優化(SEO botrawlers)(即谷歌機器人,百度,findxbot等)搜索已刪除的帖子的結果。如何防止rollbar報告搜索引擎優化爬蟲活動?
如何防止rollbar報告SEO scrawler活動。
看起來你正在使用rollbar-gem,所以你想使用Rollbar::Ignore
告訴ROLLBAR忽略由蜘蛛導致的錯誤
handler = proc do |options|
raise Rollbar::Ignore if is_crawler_error(options)
end
Rollbar.configure do |config|
config.before_process << handler
end
其中is_crawler_error
檢測是否導致錯誤的請求是來自一個爬蟲。
如果使用rollbar.js檢測客戶端JavaScript錯誤,那麼你可以使用checkIgnore
選項,以過濾掉造成的殭屍客戶端錯誤:
_rollbarConfig = {
// current config...
checkIgnore: function(isUncaught, args, payload) {
if (window.navigator.userAgent && window.navigator.userAgent.indexOf('Baiduspider') !== -1) {
// ignore baidu spider
return true;
}
// no other ignores
return false;
}
}
這裏就是我所做的:
is_crawler_error = Proc.new do |options|
return true if options[:scope][:request]['From'] == 'bingbot(at)microsoft.com'
return true if options[:scope][:request]['From'] == 'googlebot(at)googlebot.com'
return true if options[:scope][:request]['User-Agent'] =~ /Facebot Twitterbot/
end
handler = proc do |options|
raise Rollbar::Ignore if is_crawler_error.call(options)
end
config.before_process << handler
根據these docs。
我可以在哪裏獲得關於is_crawler_error方法的更多細節? –
嗨Alif - 抱歉不清楚這一點 - 你應該自己定義'is_crawler_error'(或任何方法來尋找蜘蛛)。它應該檢查請求上的用戶代理值,並將其與要阻止的已知蜘蛛列表進行比較。 –
來到這裏尋找關於如何實現處理程序忽略某些請求的配方。不知道如果這是一個可接受的答案,如果它是從文檔完整複製粘貼。 –