Created
June 13, 2013 13:59
-
-
Save yswallow/5773893 to your computer and use it in GitHub Desktop.
http://vcard.ameba.jp/giftbox でカードを枚数順に並べ替えて表示するスクリプト
This file contains hidden or 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
| # coding: UTF-8 | |
| #require "./tools" | |
| require "open-uri" | |
| require "pp" | |
| require "nokogiri" | |
| class VCard | |
| @@cookie_changed = true | |
| @@cookies = {} | |
| @@ua = "" | |
| @@cookie_str = "" | |
| def self.input_id | |
| print "game_auth_idを入力: " | |
| @@authid = gets.chomp | |
| @@cookies["gameAuthId"] = @@authid | |
| end | |
| def self.set_cookie(hash) | |
| # pp hash | |
| @@cookies.merge! hash | |
| # pp @@cookies | |
| @@cookie_changed = true | |
| end | |
| def self.make_cookie_str | |
| @@cookie_str = @@cookies.map { |cookie| cookie.join('=') }.join(';') | |
| puts @@cookie_str | |
| end | |
| def self.set_ua(type = :android) | |
| @@ua = type == :android ? | |
| "Mozilla/5.0 (Linux; U; Android 4.0.3; ja-jp; URBANO PROGRESSO Build/010.0.3000) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30" | |
| : "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25" | |
| end | |
| def self.getio( url = "http://vcard.ameba.jp/mypage") | |
| url = URI.join("http://vcard.ameba.jp/mypage",url).to_s unless /^http/ =~ url | |
| if @@cookie_changed | |
| self.make_cookie_str | |
| @@cookie_changed = false | |
| end | |
| # make_cookie_str unless @@cookie_str | |
| puts @@cookie_str | |
| begin | |
| io = open(url,'Cookie' => @@cookie_str,"User-Agent" => @@ua) | |
| rescue => ex | |
| puts ex.message,nil,ex.class | |
| pp ex.methods | |
| end | |
| end | |
| end | |
| VCard.input_id | |
| VCard.set_ua(:android) | |
| VCard.set_cookie({ "giftBox-filter" => "1" })#,"P" => "61.210.190.214.1370086971775978" | |
| io = VCard.getio("giftbox") | |
| #page = Nokogiri::HTML(io) | |
| #File.write "giftbox1.html" , page.to_html | |
| #page = Nokogiri::HTML(open("./giftbox1.html")) | |
| girls_h = Hash.new 0 | |
| #next_page = page.xpath('//a[@id="nextList"]')[0]["href"] | |
| #puts next_page | |
| loop do | |
| page = Nokogiri::HTML(io) | |
| items = page.xpath('//section[@class="giftBox dataList btmBorder"]') | |
| next_page = page.xpath('//a[@id="nextList"]')[0]["href"] | |
| #items.each { |item| puts item.to_html,"" } | |
| puts items.size | |
| items.each do |item| | |
| name = item.xpath('section[@class="textArea textListWidth"]/dl[@class="wText"]/dt[1]').text | |
| girls_h[name] += 1 | |
| end | |
| pp next_page | |
| break unless next_page | |
| io = VCard.getio(next_page) | |
| end | |
| girls_a = girls_h.to_a.sort_by { |girl| girl[1] }.reverse | |
| girls_a.each do |girl| | |
| puts "#{girl[0]} : #{girl[1]}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment