Class: WebsiteWorth::Scraper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alexa_rankObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def alexa_rank
  @alexa_rank
end

#attriObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def attri
  @attri
end

#overall_revenueObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def overall_revenue
  @overall_revenue
end

#rev_dailyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def rev_daily
  @rev_daily
end

#rev_monthlyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def rev_monthly
  @rev_monthly
end

#rev_yearlyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def rev_yearly
  @rev_yearly
end

#site_nameObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def site_name
  @site_name
end

#views_dailyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def views_daily
  @views_daily
end

#views_monthlyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def views_monthly
  @views_monthly
end

#views_yearlyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def views_yearly
  @views_yearly
end

#visits_dailyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def visits_daily
  @visits_daily
end

#visits_monthlyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def visits_monthly
  @visits_monthly
end

#visits_yearlyObject

attributes



4
5
6
# File 'lib/website_worth/scraper.rb', line 4

def visits_yearly
  @visits_yearly
end

Instance Method Details

#get_data_sourceObject



24
25
26
27
# File 'lib/website_worth/scraper.rb', line 24

def get_data_source
  @site_name = WebsiteWorth::User.gives_a_site_name
  @site = Nokogiri::HTML(open("https://www.worthofweb.com/website-value/#{site_name}/"))
end

#get_site_attributesObject



89
90
91
92
# File 'lib/website_worth/scraper.rb', line 89

def get_site_attributes
  @attri = []
  attri
end

#get_user_site_dataObject



17
18
19
20
21
22
# File 'lib/website_worth/scraper.rb', line 17

def get_user_site_data
  get_data_source
  pin_point_data
  print_data
  get_site_attributes
end

#gets_big_name_dataObject

Priority Methods



8
9
10
11
12
13
14
15
# File 'lib/website_worth/scraper.rb', line 8

def gets_big_name_data
  urls = ["https://www.worthofweb.com/website-value/google/", "https://www.worthofweb.com/website-value/amazon/", "https://www.worthofweb.com/website-value/facebook/", "https://www.worthofweb.com/website-value/youtube/"]
  worth = []
  urls.each do |url|
    worth << Nokogiri::HTML(open(url)).css('div.card-body div.side-left p:nth-of-type(2)')[0].text
  end
  worth
end

#pin_point_dataObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/website_worth/scraper.rb', line 29

def pin_point_data 
  # ========== Revenue ========== #
  begin
    @overall_revenue = @site.css('div.card-body div.side-left p:nth-of-type(2)')[0].text
  rescue NoMethodError
    puts "Sorry, it seems that the website you entered was invalid"
    WebsiteWorth::CLI.new.call
  end
  @rev_daily = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[0].text
  @rev_monthly = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[1].text
  @rev_yearly = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[2].text
  # ========== Visits ========== #
  @visits_daily = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[3].text
  @visits_monthly = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[5].text
  @visits_yearly = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[7].text
  # ========== Page Views ========== #
  @views_daily = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[4].text
  @views_monthly = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[6].text
  @views_yearly = @site.css('div.card-body .col-md-4 p:nth-of-type(2)')[8].text
  # ========== Alexa Rank ========== #
  @alexa_rank = @site.css('div.row')[25].text.gsub(/\R+/, ' ').strip.split[9]
end


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/website_worth/scraper.rb', line 52

def print_data
  puts "\n           #{@site_name.upcase}"
  get_site_attributes << @site_name.upcase
  puts
  puts "========== REVENUE =========="
  puts
  puts "===== Overall/ #{@overall_revenue} ====="
  get_site_attributes << @overall_revenue
  puts "===== Daily/ #{@rev_daily} ====="
  get_site_attributes << @rev_daily
  puts "===== Monthly/ #{@rev_monthly} ====="
  get_site_attributes << @rev_monthly
  puts "===== Yearly/ #{@rev_yearly} ====="
  get_site_attributes << @rev_yearly
  puts 
  puts "========== VISITS =========="
  puts
  puts "===== Daily/ #{@visits_daily} ====="
  get_site_attributes << @visits_daily
  puts "===== Monthly/ #{@visits_monthly} ====="
  get_site_attributes << @visits_monthly
  puts "===== Yearly/ #{@visits_yearly} ====="
  get_site_attributes << @visits_yearly
  puts 
  puts "========== PAGE VIEWS =========="
  puts
  puts "===== Daily/ #{@views_daily} ====="
  get_site_attributes << @views_daily
  puts "===== Monthly/ #{@views_monthly} ====="
  get_site_attributes << @views_monthly
  puts "===== Yearly/ #{@views_yearly} ====="
  get_site_attributes << @views_yearly
  puts 
  puts "========== Alexa Rank/ #{@alexa_rank} =========="
  get_site_attributes << @alexa_rank
end