Class: University_scraper
- Inherits:
-
Object
- Object
- University_scraper
- Defined in:
- lib/university_cli_app/university_scraper.rb
Overview
require ‘capybara/poltergeist’ require ‘pry’
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/university_cli_app/university_scraper.rb', line 5 def description @description end |
#location ⇒ Object
Returns the value of attribute location.
5 6 7 |
# File 'lib/university_cli_app/university_scraper.rb', line 5 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/university_cli_app/university_scraper.rb', line 5 def name @name end |
#rank ⇒ Object
Returns the value of attribute rank.
5 6 7 |
# File 'lib/university_cli_app/university_scraper.rb', line 5 def rank @rank end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/university_cli_app/university_scraper.rb', line 5 def url @url end |
Class Method Details
.school_list ⇒ Object
7 8 9 |
# File 'lib/university_cli_app/university_scraper.rb', line 7 def self.school_list scrape_school_list end |
.scrape_school_list ⇒ Object
11 12 13 14 15 16 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/university_cli_app/university_scraper.rb', line 11 def self.scrape_school_list # options = { # js_errors: false, # } .register_driver :poltergeist do |app| ::Poltergeist::Driver.new(app, js_errors: false, phantomjs_logger: StringIO.new) end session = ::Session.new(:poltergeist) doc = session.visit('https://www.thebestcolleges.org/rankings/top-50/') session.find('.js-rankings-expand-all').click #puts session.document.title list = [] session.all('table.rankings-list tbody tr').each do |item| list << { :rank => item.find('td.rank').text, :name => item.find('td.title a.rank-title-link').text, :location => item.find('td.title span.label').text, :url => item.find('td.stat.link a')['href'], :description => item.first("td.stat.copy p").text } end #binding.pry list end |