-
Notifications
You must be signed in to change notification settings - Fork 0
/
tennis_parser.rb
47 lines (39 loc) · 1.21 KB
/
tennis_parser.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
require 'nokogiri'
require_relative 'tennis_slot'
class TennisParser
@@host = 'https://teleservices.paris.fr'
# get the research pages links
def self.get_links(html)
parsed_html = Nokogiri::HTML(html)
result = parsed_html.css('span.pagelinks/a/@href')
result[0..-3].map { |x| @@host + x }
end
def self.parse_page(html)
trs = Nokogiri::HTML(html).xpath('//tbody/tr')
trs.map { |tr| parse_column(tr.to_s) }
end
def self.parse_column(tr)
columns = Nokogiri.XML(tr).xpath('//td')
TennisSlot.new(
columns[0].text,
columns[2].text,
columns[3].text,
columns[4].text.scan( /(\d*)/)[-2].first.to_i,
get_reservation_keys(columns.last.children.first.attribute('href').to_s)
)
end
def self.get_reservation_keys(string)
array = string.split('\'')
{cle: array[1], libelleReservation: array[5], rechercheElargie: '' }
end
def self.get_next_link(html)
parsed_html = Nokogiri::HTML(html)
result = parsed_html.css('span.pagelinks/a/@href')
@@host + result[-2]
end
def self.next_link?(html)
parsed_html = Nokogiri::HTML(html)
result = parsed_html.css('span.pagelinks/a')
result.select { |a| a.text == 'Suivant' }.size == 1
end
end