Module: Scrappy::BlindAgent
- Included in:
- Agent
- Defined in:
- lib/scrappy/agent/blind_agent.rb
Instance Method Summary collapse
- #html ⇒ Object
- #html_data? ⇒ Boolean
- #initialize(args = {}) ⇒ Object
- #uri ⇒ Object
- #uri=(uri) ⇒ Object
Instance Method Details
#html ⇒ Object
36 37 38 |
# File 'lib/scrappy/agent/blind_agent.rb', line 36 def html @mechanize.current_page.root.to_html :encoding=>'UTF-8' end |
#html_data? ⇒ Boolean
32 33 34 |
# File 'lib/scrappy/agent/blind_agent.rb', line 32 def html_data? !uri.nil? and @mechanize.current_page.is_a?(Mechanize::Page) end |
#initialize(args = {}) ⇒ Object
3 4 5 6 7 |
# File 'lib/scrappy/agent/blind_agent.rb', line 3 def initialize args={} super() @mechanize = Mechanize.new @mechanize.max_history = 20 end |
#uri ⇒ Object
9 10 11 |
# File 'lib/scrappy/agent/blind_agent.rb', line 9 def uri @loaded ? @mechanize.current_page.uri.to_s : nil end |
#uri=(uri) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/scrappy/agent/blind_agent.rb', line 13 def uri= uri synchronize do retries = 10 @loaded = false while retries > 0 and !@loaded begin @mechanize.get uri @loaded = true rescue Timeout::Error @loaded = false rescue @loaded = false end retries -= 1 unless @loaded end @loaded end end |