Last active
May 10, 2017 08:31
-
-
Save s4kr4/cf29a6fbceabe56e33f1aafb234dec5c to your computer and use it in GitHub Desktop.
Get Cinderella Girls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'Oga' | |
base_uri = "http://imas.gamedbs.jp" | |
def open_uri(uri) | |
html = open(uri) do |f| | |
f.read | |
end | |
Oga.parse_html(html) | |
end | |
begin | |
# トップページ読み込み | |
doc = open_uri(base_uri + "/cg") | |
# 詳細ページリンクを取る | |
detail_uris = [] | |
doc.xpath('//*[@id="result"]/ul/li/a').each do |node| | |
detail_uris.push(node.get('href')) | |
end | |
# 詳細ページ読み込み | |
detail_uris.each do |detail_uri| | |
idle_doc = open_uri(base_uri + detail_uri) | |
# 個別のカードページURLを取得 | |
card_uris = [] | |
idle_doc.xpath('//*[@id="gallery"]/div[5]/div/div/div/a').each do |node| | |
card_uris.push(node.get('href')) | |
end | |
# 個別のカードページ読み込み | |
idle_info = [] | |
card_uris.each_with_index do |card_uri, i| | |
if i % 2 == 0 | |
card_doc = open_uri("http:" + card_uri) | |
for n in 1..2 do | |
tmp = {} | |
card_doc.xpath('//*[@id="cards"]/ul/li[' + n.to_s + ']/h2').map{|n| | |
info = n.text.strip.gsub(" ", "").split("\n") | |
# rank = info[0] | |
# name = info[1] | |
tmp["rank"] = info[0] | |
tmp["name"] = info[1] | |
} | |
card_doc.xpath('//*[@id="cards"]/ul/li[' + n.to_s + ']/div/div[1]/ul/li[1]/a/img').map{|n| | |
tmp["img"] = n.attributes[1].value | |
} | |
idle_info.push(tmp) | |
end | |
end | |
p "idle_info" | |
p idle_info | |
end | |
end | |
rescue Interrupt | |
p 'QUIT!' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment