Skip to content

Instantly share code, notes, and snippets.

@clicube
Created February 8, 2013 17:13
Show Gist options
  • Save clicube/4740449 to your computer and use it in GitHub Desktop.
Save clicube/4740449 to your computer and use it in GitHub Desktop.
HumanlikeMechanize waits before each get/post
require 'mechanize'
class HumanlikeMechanize < Mechanize
def initialize min,max
raise ArgumentError.new("min > max") if min > max
raise ArgumentError.new("min < 0") if min < 0
raise ArgumentError.new("max < 0") if max < 0
@sleep_min = min
@sleep_max = max
super()
end
def sleep
sleeptime = @sleep_min + rand(@sleep_max-@sleep_min+1)
Kernel.sleep sleeptime
end
def get *args
self.sleep
super
end
def post *args
self.sleep
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment