class GooglePlayScraper::Parser
Constants
- LOGO_CSS_SELECTOR
Attributes
raw_html[R]
Public Class Methods
new(raw_html)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 9 def initialize(raw_html) @raw_html = raw_html end
Public Instance Methods
create_app(app_container)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 29 def create_app(app_container) app = GooglePlayScraper::App.new app.logo_url = extract_logo_url(app_container) app.logo_url_small = extract_logo_url_small(app_container) app.url = extract_app_url(app_container) app.id = extract_app_id(app_container) app.name = extract_app_name(app_container) app.developer = extract_developer(app_container) app end
extract_app_id(app_container)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 51 def extract_app_id(app_container) a_tag = app_container.css('.card-content a.card-click-target').first uri = Addressable::URI.parse(a_tag['href']) uri.query_values['id'] end
extract_app_name(app_container)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 46 def extract_app_name(app_container) a_tag = app_container.css('.card-content .details a.title').first a_tag['title'] end
extract_app_url(app_container)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 57 def extract_app_url(app_container) a_tag = app_container.css('.card-content a.card-click-target').first GooglePlayScraper::GOOGLE_PLAY_BASE_URL + a_tag['href'] end
extract_developer(app_container)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 41 def extract_developer(app_container) span_tag = app_container.css('.card-content .details .subtitle-container .subtitle').first span_tag.content end
extract_logo_url(app_container)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 62 def extract_logo_url(app_container) img_tag = app_container.css(LOGO_CSS_SELECTOR).first img_tag['data-cover-large'] end
extract_logo_url_small(app_container)
click to toggle source
# File lib/google_play_scraper/parser.rb, line 67 def extract_logo_url_small(app_container) img_tag = app_container.css(LOGO_CSS_SELECTOR).first img_tag['data-cover-small'] end
results()
click to toggle source
# File lib/google_play_scraper/parser.rb, line 13 def results doc = Nokogiri::HTML(raw_html) unless doc.css('.card').any? raise 'Could not parse app store results page' end results = [] doc.css('.card').each do |app_container| results << create_app(app_container) end results end