Sha256: 30e137642b939e2dc79a657c5f8ad058b06cde910e0578a8aa99ff400a30f80e
Contents?: true
Size: 1.17 KB
Versions: 7
Compression:
Stored size: 1.17 KB
Contents
class TopStockMovers::Stocks attr_accessor :ticker_symbol, :name, :price, :percent_change, :change, :rating, :sector, :url, :volume, :market_cap @@all = [] def self.all @@all end def self.scrape_tradingview(category) doc = Nokogiri::HTML(open("https://www.tradingview.com/markets/stocks-usa/market-movers-#{category}/")) doc.css('body div div#js-category-content div div div div#js-screener-container div table tbody tr').each do |row| stock = self.new stock.url = "https://www.tradingview.com#{row.css('a').attr('href').value}" stock_info = row.css('td').collect{|td| td.text} stock.ticker_symbol = stock_info[0].split("\n\t\t\t\t\t\t").reject{|c| c.empty?}[0] stock.name = stock_info[0].split("\n\t\t\t\t\t\t").reject{|c| c.empty?}[1].gsub(/INC|LTD|PLC|3X|LLC|BOND|SPONSORED|\s{2,}|[,(-]/, "++").split("++")[0] stock.price = stock_info[1].to_f stock.percent_change = stock_info[2].to_f stock.change = stock_info[3].to_f stock.rating = stock_info[4] stock.volume = stock_info[5].to_f stock.market_cap = stock_info[6].to_f.round(1) stock.sector = stock_info[10] @@all << stock end end end
Version data entries
7 entries across 7 versions & 1 rubygems