Class: Stockbot

Inherits:
Object
  • Object
show all
Defined in:
lib/stockbot.rb

Class Method Summary collapse

Class Method Details

.showinfoObject



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
# File 'lib/stockbot.rb', line 9

def self.showinfo

    prefix = ['NUMBER',*'a'..'z']

    prefix.each do |e|
        html = URI.open("https://www.set.or.th/set/commonslookup.do?prefix=#{e}")
        response = Nokogiri::HTML(html)


        response.css("tr td a").each do |x|
            detail_url = 'https://www.set.or.th' + x["href"]
            detail_page = URI.open(detail_url)
            detail = Nokogiri::HTML(detail_page)
            name = detail.css("div h3").text

            # get assests
            detail_url["profile"] = "highlight"
            assests_page = URI.open(detail_url)
            assests = Nokogiri::HTML(assests_page)
            lastest_assests = assests.css("#maincontent > div > div.table-responsive > table > tbody:nth-child(3) > tr:nth-child(2) > td:nth-last-child(-n+2)").text

            unless !lastest_assests.strip.empty?
                lastest_assests = assests.css("#maincontent > div > div.table-responsive > table > tbody:nth-child(3) > tr:nth-child(2) > td:nth-last-child(-n+2)").text
            end

            puts "#{name} : #{lastest_assests}"
        end
    end
end