class StockJustA

Public Class Methods

scraper() click to toggle source
# File lib/stockjusta.rb, line 7
def self.scraper
    n = 0
    url = "https://www.set.or.th/set/commonslookup.do"
    unp_page = URI.open(url)
    p_page = Nokogiri::HTML(unp_page)
    companies = Array.new
    company_listings = p_page.css('tr')
    company_listings.each do |company_lsitings|
        name = Nokogiri::HTML(URI.open("https://www.set.or.th"+company_listings.css('td a')[n].values[0])).css('div.row').css('h3').text
        url =  "https://www.set.or.th"+company_listings.css('td a')[n].values[0]
        url["profile"] = "highlight"
        highlight = Nokogiri::HTML(URI.open(url)).css('#maincontent > div > div.table-responsive > table > tbody:nth-child(3) > tr:nth-child(2) > td:nth-child(5)').text 
        if highlight.empty?
            highlight = "ไม่มีบอกไว้"
        end
        n+=1
        puts name + " : " + highlight
        rescue NoMethodError
    end
end