Skip to content

Instantly share code, notes, and snippets.

@ohnishiakira
Created March 20, 2011 14:27
Show Gist options
  • Save ohnishiakira/878349 to your computer and use it in GitHub Desktop.
Save ohnishiakira/878349 to your computer and use it in GitHub Desktop.
Access to shindanmaker.com by using ruby & Nokogiri.
#!/usr/bin/env ruby
# coding: utf-8
require "rubygems"
require "net/http"
require "nokogiri"
class ShindanMaker
attr_accessor :user, :yomi, :path
def initialize(user = "", yomi = "", path = 0)
@user = user
@yomi = yomi
@http = Net::HTTP.start("shindanmaker.com")
@path = path == 0 ? random : path
end
# pathが空だった場合に適当にpathを指定する
def random
list = {
:new => 5, # 新着診断
:hot => 7, # HOT診断
:pickup => 9, # PICKUP診断
:yesterday => 11, # 昨日の診断ランキング
:all => 13 # 総合ランキング
}
body = @http.get("/").body
html = Nokogiri::HTML(body)
v = html.css("div.blue > div")[list[:new]].css("a")[0].attributes["href"].value
if v =~ /\d+/ then
@path = $&
end
end
def post
body = @http.post("/#{@path}", "u=#{@user}").body
Nokogiri::HTML(body).css("div.result div").text.split[0]
end
end
user = "ohnishiakira"
yomi = "おおにしあきら"
s = ShindanMaker.new(user, yomi)
puts s.post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment