Class: GooglePlayDevScraper::ScraperBase
- Inherits:
-
Object
- Object
- GooglePlayDevScraper::ScraperBase
- Defined in:
- lib/googleplay_dev_scraper/scraper_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize ⇒ ScraperBase
constructor
A new instance of ScraperBase.
- #setup ⇒ Object
- #try_get(url) ⇒ Object
Constructor Details
#initialize ⇒ ScraperBase
Returns a new instance of ScraperBase.
17 18 19 20 |
# File 'lib/googleplay_dev_scraper/scraper_base.rb', line 17 def initialize @agent = nil @config = ScraperConfig.new end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
14 15 16 |
# File 'lib/googleplay_dev_scraper/scraper_base.rb', line 14 def agent @agent end |
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/googleplay_dev_scraper/scraper_base.rb', line 15 def config @config end |
Instance Method Details
#setup ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/googleplay_dev_scraper/scraper_base.rb', line 22 def setup #Mechanize.log = Logger.new("mechanize.log") #Mechanize.log.level = Logger::INFO unless @agent @agent = Mechanize.new end if @config.proxy_host && @config.proxy_host.length >= 1 @agent.set_proxy(@config.proxy_host, @config.proxy_port) end end |
#try_get(url) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/googleplay_dev_scraper/scraper_base.rb', line 34 def try_get(url) unless @agent setup end # try to get @agent.get(url) # login needed? if @agent.page.uri.host != "accounts.google.com" || @agent.page.uri.path != "/ServiceLogin" # already login-ed return end # do login form = @agent.page.forms.find {|f| f.form_node['id'] == "gaia_loginform"} unless form raise 'No login form' end form.field_with(:name => "Email").value = @config.email form.field_with(:name => "Passwd").value = @config.password form. if @agent.page.uri.host == "accounts.google.com" STDERR.puts "login failed? : uri = " + @agent.page.uri.to_s raise 'Google login failed' end # retry get @agent.get(url) end |