Class: WebsiteWorth::Scraper
- Inherits:
-
Object
- Object
- WebsiteWorth::Scraper
- Defined in:
- lib/website_worth/scraper.rb
Instance Attribute Summary collapse
-
#alexa_rank ⇒ Object
attributes.
-
#attri ⇒ Object
attributes.
-
#overall_revenue ⇒ Object
attributes.
-
#rev_daily ⇒ Object
attributes.
-
#rev_monthly ⇒ Object
attributes.
-
#rev_yearly ⇒ Object
attributes.
-
#site_name ⇒ Object
attributes.
-
#views_daily ⇒ Object
attributes.
-
#views_monthly ⇒ Object
attributes.
-
#views_yearly ⇒ Object
attributes.
-
#visits_daily ⇒ Object
attributes.
-
#visits_monthly ⇒ Object
attributes.
-
#visits_yearly ⇒ Object
attributes.
Instance Method Summary collapse
- #get_data_source ⇒ Object
- #get_site_attributes ⇒ Object
- #get_user_site_data ⇒ Object
-
#gets_big_name_data ⇒ Object
Priority Methods.
- #pin_point_data ⇒ Object
- #print_data ⇒ Object
Instance Attribute Details
#alexa_rank ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def alexa_rank @alexa_rank end |
#attri ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def attri @attri end |
#overall_revenue ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def overall_revenue @overall_revenue end |
#rev_daily ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def rev_daily @rev_daily end |
#rev_monthly ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def rev_monthly @rev_monthly end |
#rev_yearly ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def rev_yearly @rev_yearly end |
#site_name ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def site_name @site_name end |
#views_daily ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def views_daily @views_daily end |
#views_monthly ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def views_monthly @views_monthly end |
#views_yearly ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def views_yearly @views_yearly end |
#visits_daily ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def visits_daily @visits_daily end |
#visits_monthly ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def visits_monthly @visits_monthly end |
#visits_yearly ⇒ Object
attributes
4 5 6 |
# File 'lib/website_worth/scraper.rb', line 4 def visits_yearly @visits_yearly end |
Instance Method Details
#get_data_source ⇒ Object
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_attributes ⇒ Object
89 90 91 92 |
# File 'lib/website_worth/scraper.rb', line 89 def get_site_attributes @attri = [] attri end |
#get_user_site_data ⇒ Object
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_data ⇒ Object
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_data ⇒ Object
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 |
#print_data ⇒ Object
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 |