Skip to content

Instantly share code, notes, and snippets.

@gizipp
Created October 11, 2020 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gizipp/1f972838e211ea6af64d8949d4594960 to your computer and use it in GitHub Desktop.
Save gizipp/1f972838e211ea6af64d8949d4594960 to your computer and use it in GitHub Desktop.
Scrapes and parses application from the Google Play Store by query
require 'mechanize'
require 'pry'
require 'csv'
query = 'racing multiplayer'
agent = Mechanize.new
page = agent.get("https://play.google.com/store/search?q=#{query}&c=apps")
top_50_apps_links = []
page.links.each do |link|
top_50_apps_links << link.href if link.href.include?("/store/apps/details?")
end
puts "Fetch all urls"
top_50_apps_links.uniq!
CSV.open("#{query}.csv", "wb") do |csv|
csv << ["name", "link", "install", "rate", "review"]
top_50_apps_links.each do |link|
page = agent.get('https://play.google.com' + link)
puts "Fetch url: #{link}"
name = page.css('h1').text
install = page.search('h2')[3].parent.parent
.children[1].children[0]
.children[2].children[1].text rescue nil
rate = page.search('h2')[1].parent.parent
.children[1].children[0]
.children[0].text rescue nil
review = page.search('h2')[1].parent.parent
.children[1].children[0]
.children[2].children[1].text rescue nil
csv << [name, link, install, rate, review]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment