Created
February 8, 2013 17:13
-
-
Save clicube/4740449 to your computer and use it in GitHub Desktop.
HumanlikeMechanize waits before each get/post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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