module BeatportPlay::Scraper

Constants

VERSION

Public Class Methods

get_top_10() click to toggle source

Returns an enumerable containing the title of each song in the Beatport Top 10.

# File lib/beatport_play-scraper/scraper.rb, line 8
def self.get_top_10
  song_titles = []

  doc = Nokogiri::HTML(open('http://beatport.com'))

  # Every Beatport Top 10 song has a div.playWrapper that has a child
  # span.play-queue.play-queue-medium element with a json-data attribute that
  # contains all the song data.
  doc.css('div.playWrapper > span.play-queue.play-queue-medium').each do |song|
    # In here we have access to the 'data-json' attribute of each song.
    song_titles << JSON.parse(song['data-json'])['title']
  end

  song_titles
end