class Mozart::Scraper
Public Instance Methods
get_page()
click to toggle source
# File lib/mozart/scraper.rb, line 7 def get_page Nokogiri::HTML(open('https://en.wikipedia.org/wiki/List_of_symphonies_by_Wolfgang_Amadeus_Mozart')) end
get_symphony_page(url)
click to toggle source
# File lib/mozart/scraper.rb, line 32 def get_symphony_page(url) Nokogiri::HTML(open(url)) end
print_symphonies_index()
click to toggle source
# File lib/mozart/scraper.rb, line 20 def print_symphonies_index Mozart::Symphony.all.each.with_index do |el, index| puts "#{index+1}.\t#{el.name[/(.*)\s/,1]}" end nil end
print_symphonies_urls()
click to toggle source
# File lib/mozart/scraper.rb, line 27 def print_symphonies_urls Mozart::Symphony.all.each.with_index { |el, index| puts "#{index+1}.\t#{el.url}" } nil end
print_the_title()
click to toggle source
# File lib/mozart/scraper.rb, line 11 def print_the_title puts " #{self.get_page.css('h1').text}" end
scrape_symphonies_index()
click to toggle source
# File lib/mozart/scraper.rb, line 16 def scrape_symphonies_index self.get_page.css(".sorttext")[0..60].each { |el| Mozart::Symphony.new("#{el.text}, #{el.css("a").attr("title").text}", "https://en.wikipedia.org" + el.css("a").attr("href").text) } end
scrape_symphony_description(url)
click to toggle source
# File lib/mozart/scraper.rb, line 40 def scrape_symphony_description(url) self.get_symphony_page(url).css("p").text end
scrape_symphony_name_with_number(url)
click to toggle source
# File lib/mozart/scraper.rb, line 36 def scrape_symphony_name_with_number(url) self.get_symphony_page(url).css(".mw-parser-output p b").text end