bate's blog

調べたこと実装したことなどを取りとめもなく書きます。

AndroidのPlayStoreランキング

rubyとnokogiriでPlayStoreランキングを取得。
順位とアプリ名だけ。
AppStoreみたいに配信すればいいのに。

require 'open-uri'
require 'rubygems'
require 'nokogiri'

url='https://play.google.com/store/apps/collection/topgrossing'

charset=nil
html=open(url) do |f|
   charset=f.charset
   f.read
end

doc=Nokogiri::HTML.parse(html, nil, charset)

p doc.title

order=1
doc.xpath('//div[@class="card-list"]').each do |node|
   node.xpath('//div[@class="details"]/h2/a[@class="title"]').each do |c|
      p order.to_s+c.text
      order+=1
   end
end