Class: Relaton::Ecma::PageFetcher
- Inherits:
-
Object
- Object
- Relaton::Ecma::PageFetcher
- Defined in:
- lib/relaton/ecma/page_fetcher.rb
Instance Method Summary collapse
-
#get(url) ⇒ Mechanize::Page
Get page with retries.
-
#initialize ⇒ PageFetcher
constructor
A new instance of PageFetcher.
Constructor Details
#initialize ⇒ PageFetcher
Returns a new instance of PageFetcher.
4 5 6 7 |
# File 'lib/relaton/ecma/page_fetcher.rb', line 4 def initialize @agent = Mechanize.new @agent.user_agent_alias = Mechanize::AGENT_ALIASES.keys[rand(21)] end |
Instance Method Details
#get(url) ⇒ Mechanize::Page
Get page with retries
16 17 18 19 20 21 22 23 24 |
# File 'lib/relaton/ecma/page_fetcher.rb', line 16 def get(url) 3.times do |n| sleep n doc = @agent.get url return doc rescue StandardError => e Util.error e. end end |