Created
June 14, 2013 15:38
-
-
Save yswallow/5782806 to your computer and use it in GitHub Desktop.
vcard.ameba.jp で戦いやすい相手を探す
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 "./tools2" | |
| require "pp" | |
| require 'json' | |
| require "nokogiri" | |
| VCard.set_ua | |
| baseurl = "http://vcard.ameba.jp/battle/battle-detail?enemyId=" | |
| 10.times do | |
| io = VCard.getio("/battle/ajax/battle-user-search?cond=level") | |
| content = io.read | |
| puts io.content_encoding | |
| #puts content | |
| users = JSON.parse(content)["data"] | |
| users.each do |user| | |
| id = user["userId"].to_s | |
| # puts user["level"],"" | |
| io = VCard.getio(baseurl + id) | |
| page = Nokogiri::HTML(io) | |
| summary = page.xpath("//section[@class='textArea']/dl/div") | |
| enemy_spec_h = {} | |
| summary.each do |item| | |
| name = item.xpath("dt").text.slice(0...-1) | |
| value = item.xpath("dd").text | |
| key,val = case name | |
| when "Lv" | |
| [ :lv, value.to_i ] | |
| when "守コスト" | |
| [ :cost, value.to_i ] | |
| when "クラスランク" | |
| [ :rank, value.to_i ] | |
| else | |
| [ name, value ] | |
| end | |
| enemy_spec_h[key] = val | |
| end | |
| mens_point = page.xpath('//p[@id="mPoint"]/span[@class="mPoint"]') | |
| enemy_spec_h[:pt] = mens_point.text.to_i | |
| enemy_spec_h[:id] = id | |
| # enemies << enemy_spec_h | |
| if enemy_spec_h[:cost] <= 120 | |
| print "id: #{id},cost: #{enemy_spec_h[:cost]},point: #{enemy_spec_h[:pt]}\n" | |
| end | |
| end | |
| end | |
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 "open-uri" | |
| require "pp" | |
| require "net/http" | |
| class VCard | |
| @@cookie_changed = true | |
| @@cookies = {} | |
| @@ua = "" | |
| @@cookie_str = "" | |
| def self.input_id | |
| print "game_auth_idを入力: " | |
| @@authid = gets.chomp | |
| @@cookies["gameAuthId"] = @@authid | |
| @@cookie_changed = true | |
| 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",hash = {}) | |
| url = URI.join("http://vcard.ameba.jp/mypage",url).to_s unless /^http/ =~ url | |
| self.input_id unless @@cookies["gameAuthId"] | |
| if @@cookie_changed | |
| self.make_cookie_str | |
| @@cookie_changed = false | |
| end | |
| options = {'Cookie' => @@cookie_str,"User-Agent" => @@ua}.merge hash | |
| # make_cookie_str unless @@cookie_str | |
| #puts @@cookie_str | |
| begin | |
| io = open(url,options) | |
| rescue => ex | |
| puts ex.message,nil,ex.class | |
| pp ex.methods | |
| end | |
| end | |
| def self.post(url,data = "",settings_h = {}) | |
| url = URI.join("http://vcard.ameba.jp/mypage",url).to_s unless /^http/ =~ url | |
| self.input_id unless @@cookies["gameAuthId"] | |
| self.set_ua if @@ua.empty? | |
| if @@cookie_changed | |
| self.make_cookie_str | |
| @@cookie_changed = false | |
| end | |
| uri = URI.parse(url) | |
| header = { | |
| "Cookie" => @@cookie_str, | |
| "User-Agent" => @@ua }.merge(settings_h) | |
| io = Net::HTTP.new(uri.host) | |
| # puts uri.host,uri.path,data,header | |
| response = io.post(uri.path,data,header) rescue puts( $!, $@,responce.body) | |
| return response | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment