-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.rb
65 lines (53 loc) · 1.56 KB
/
client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# coding: utf-8
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'json'
require 'uri'
class BoatDataClient
def get_html(url)
html = open(url)
return Nokogiri::HTML(html)
end
def parse_race_list(date="20161008")
url = "http://app.boatrace.jp/race/?day=20161008"
doc = get_html(url)
list_body = doc.css(".unitRaceInfo tbody")
races = []
list_body.css("tr").each do |tr|
url = "http://app.boatrace.jp#{tr.css(".title a").attr("href").to_s}"
uri_info = URI::parse(url)
info = {
:base_url => url.split("?")[0],
:query => Hash[URI::decode_www_form(uri_info.query)],
:day => tr.css(".day").text.strip,
:title => tr.css(".title a").text,
:grade => tr.css(".grade img").attr("alt").to_s
}
races.push info
end
prev_path = doc.css(".prev a").css(".txt").attr("href").to_s
return { :prev => "http://app.boatrace.jp#{prev_path}", :races => races }
end
def parse_cup_page()
url = "http://app.boatrace.jp/race/13_20160112.php?day=20160117&jyo=13&rno=01&type=before_info" # test
html = open(url)
doc = Nokogiri::HTML(html)
rounds_num = doc.css(".roundsNav li").count
title = doc.css(".ttlArea h1").text
location = doc.css(".ttlArea img").attr("alt").to_s
res = {
:rounds => rounds_num,
:title => title,
:location => location
}
#.css(".li").each do |li|
# p li
#end
p res
end
def parse_race_result_page(day, rno)
end
end
c = BoatDataClient.new
p c.parse_race_list