module PlayScrape
Constants
- APP_ADDITIONAL_INFO_CSS_PATH
- APP_DESC_CSS_PATH
- APP_DEV_URL_CSS_PATH
- APP_ICON_CSS_PATH
- APP_NAME_CSS_PATH
- APP_NUM_RATINGS_CSS_PATH
- APP_RATING_CSS_PATH
- INSTALLS_REGEX
- PLAY_URL
- URL_REGEX
- VERSION
- VERSION_REGEX
Public Class Methods
get_html_page_for(package_name)
click to toggle source
# File lib/play_scrape.rb, line 64 def self.get_html_page_for(package_name) res = Typhoeus.get(PLAY_URL + package_name) end
scrape_app_icon(package_name)
click to toggle source
# File lib/play_scrape.rb, line 68 def self.scrape_app_icon(package_name) res = self.get_html_page_for(package_name) if res html = Nokogiri::HTML(res.body) icon = html.css(APP_ICON_CSS_PATH).first if icon icon.attributes['src'].value else nil end else nil end end
scrape_app_info(package_name)
click to toggle source
Returns @app_info of AppInfo
class
# File lib/play_scrape.rb, line 25 def self.scrape_app_info(package_name) res = self.get_html_page_for(package_name) if res.code == 200 app_info = PlayScrape::AppInfo.new html = Nokogiri::HTML(res.body) name = html.css(APP_NAME_CSS_PATH).first description = html.css(APP_DESC_CSS_PATH).first app_rating = html.css(APP_RATING_CSS_PATH).first num_ratings = html.css(APP_NUM_RATINGS_CSS_PATH).first icon_url = html.css(APP_ICON_CSS_PATH).first # A bit hacky below but it'll do installs_text = html.css(APP_ADDITIONAL_INFO_CSS_PATH)[2].text.strip installs = installs_text.gsub(",", "").split("-").map(&:to_i) if installs_text.match(INSTALLS_REGEX) version_text = html.css(APP_ADDITIONAL_INFO_CSS_PATH)[3].text.strip version = version_text if version_text.match(VERSION_REGEX) dev_links = html.css(APP_DEV_URL_CSS_PATH) dev_url = "" if !dev_links.empty? && dev_links.first.text.match(/Visit Developer's Website/) dev_url = dev_links.first.attributes['href'].value.match(URL_REGEX)[1] end app_info.app_name = name.text app_info.package_name = package_name app_info.description = description.inner_html app_info.rating = app_rating.text.to_f app_info.num_ratings = num_ratings.text.gsub(",", "").to_i app_info.icon_url = icon_url.attributes['src'].value app_info.dev_url = dev_url app_info.min_installs = installs.first app_info.max_installs = installs.last app_info.version = version app_info end end