class SetResult

Public Class Methods

main() click to toggle source
# File lib/set_results.rb, line 8
def self.main
    html = URI.open("https://www.set.or.th/set/commonslookup.do")
    response = Nokogiri::HTML(html)
    link = response.css('div.capital-letter a').map { |link| link['href'] }
    link.each do |each_page|
        html = URI.open("https://www.set.or.th#{each_page}")
        response = Nokogiri::HTML(html)
        links = response.css("td a").each do |each_link|
            real_link = each_link.attributes["href"].value.gsub('companyprofile','companyhighlight')
            each_html = URI.open("https://www.set.or.th#{real_link}")
            each_response = Nokogiri::HTML(each_html)
            name = each_response.css("h3").text
            price = each_response.css("tr[2]").text
            split_price = price.split
            split_price.reverse.each do |i|
                x = i.gsub(',','')
                float_x = x.to_f
                if float_x.kind_of? Float
                    if float_x != 0.0
                        price = i
                        break
                    else 
                        price = 'Not found'
                    end
                end
            end
            puts"#{name} : #{price}"
        end
    end
end