class GooglePlayDevScraper::ScraperBase
Attributes
agent[RW]
config[RW]
Public Class Methods
new()
click to toggle source
# File lib/googleplay_dev_scraper/scraper_base.rb, line 17 def initialize @agent = nil @config = ScraperConfig.new end
Public Instance Methods
setup()
click to toggle source
# 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)
click to toggle source
# 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.click_button 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