Class: StockcliApp::Scraper

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

Overview

The Scraper class should have two methods The first method should be used to scrape the name, symbol, market cap The first method should return an array with arrays for each stock within it : This should be information collected from the main webpage about the 8 large companies url etc. from the main page for all the stocks The second method should scrape information about the individual stock The second method should scrape the EPS P/E ratio and the Index

Class Method Summary collapse

Class Method Details

.scrape_screenerObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stockcli_app/scraper.rb', line 17

def self.scrape_screener
  array_main = []
  finviz = Nokogiri::HTML(open("https://finviz.com/screener.ashx?v=111&f=cap_mega,exch_nasd"))
  fin = finviz.css("div#screener-content").css("td").css("tr[valign=top]")

  fin.each do |f|
       temp = []

       num = f.css("td")[0].text
       symbol = f.css("td")[1].text
       name = f.css("td")[2].text
       url = f.css("td")[1].css("a").attribute("href").value

       price = f.css("td")[8].text
       mktcap = f.css("td")[6].text
       sector = f.css("td")[3].text
       change = f.css("td")[9].text

       temp = [num, symbol, name, url, price, mktcap, sector, change]
       array_main << temp
     end
  array_main
end

.scrape_stock_info(url) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/stockcli_app/scraper.rb', line 41

def self.scrape_stock_info(url)
  stock_webpage = Nokogiri::HTML(open(url))
  stock_addinfo_array = []
  stock = stock_webpage.css("table.snapshot-table2 tr")
    index = stock.css("td")[1].text
    peratio = stock.css("td")[3].text
    eps = stock.css("td")[5].text
  stock_addinfo_array = [index, peratio, eps]
end