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
|
# File 'lib/set-scraper.rb', line 7
def self.set
html = URI.open("https://www.set.or.th/set/commonslookup.do")
response = Nokogiri::HTML(html)
description = response.css("div.row[3] div a").each do |each_page|
each_html = URI.open("https://www.set.or.th#{each_page.attributes["href"].value}")
response = Nokogiri::HTML(each_html)
description = response.css("tr").each_with_index do |obj, index|
next if index == 0
full_name = obj.css("td[2]").text
short_name = obj.css("td a").text
url = "https://www.set.or.th" + obj.css("td a")[0].attributes["href"].value
url_assert = url.gsub("profile", "highlight")
assert_html = URI.open(url_assert)
response_assert = Nokogiri::HTML(assert_html)
description_assert = response_assert.css("div.table-responsive").css("table[1]").css("tbody").css("tr[2] td")
assert_list = []
description_assert.each do |obj|
if (obj != nil)
temp = obj.text.strip.gsub(',','').to_f
if (temp != 0.0)
assert_list.push(temp)
end
end
end
assert = assert_list.length == 0 ? "Not found!!" : assert_list[-1].to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
puts "#{short_name} : #{full_name} : #{assert}"
end
end
end
|