Class: TopGeniusSongs::Scraper
- Inherits:
-
Object
- Object
- TopGeniusSongs::Scraper
- Defined in:
- lib/top_genius_songs/scraper.rb
Class Method Summary collapse
Class Method Details
.get_lyrics(url) ⇒ Object
15 16 17 18 |
# File 'lib/top_genius_songs/scraper.rb', line 15 def self.get_lyrics(url) page = Nokogiri::HTML(open(url)) page.search('.lyrics p').text.strip end |
.scrape ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/top_genius_songs/scraper.rb', line 2 def self.scrape page = Nokogiri::HTML(open("http://genius.com/")) page.search(".song_card").each do |song| TopGeniusSongs::Song.all << TopGeniusSongs::Song.new.tap do |s| s.title = song.search(".song_card-title").text s.artist = song.search(".song_card-artist").text s.description = song.search(".song_card-description").text.strip s.link = song.search("a")[0].attributes["href"].value end end TopGeniusSongs::Song.all end |