Sha256: 37b5b5785939884c208eececd3a37be66d9cf1004d34ae791eb145fcb18362bf
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
class BillboardHot100Songs::Scraper BASE_PATH = "https://www.billboard.com/charts/hot-100" def self.scrape_main_page page_data = Nokogiri::HTML(open(BASE_PATH)) # BACKUP HTML FOR OFFLINE USE # To work offline, run the extractor in the backup_website folder to parse data you want to save # To run the extractor, cd into the 'backup_website' directory. Then in your terminal enter: 'ruby extractor.rb' # Then uncomment the next two lines below (lines 12 and 13) and comment above code + BASE_PATH (lines 3 and 7) # html_backup = File.read('lib/billboard_hot_100_songs/backup_website/billboard_hot_100_songs.html') # page_data = Nokogiri::HTML(html_backup) page_data.css("li.chart-list__element").map do |element| song = {} song[:name] = element.css("span.chart-element__information__song").text song[:artist] = element.css("span.chart-element__information__artist").text song[:rank_this_week] = element.css("span.chart-element__rank__number").text song[:delta] = element.css("span.chart-element__information__delta__text.text--default").text song[:rank_last_week] = element.css("span.chart-element__information__delta__text.text--last").text.gsub(" Last Week","") song[:peak_rank] = element.css("span.chart-element__information__delta__text.text--peak").text.gsub(" Peak Rank","") song[:duration] = element.css("span.chart-element__information__delta__text.text--week").text.gsub(" Weeks on Chart","") song end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
billboard_hot_100_songs-1.0.1 | lib/billboard_hot_100_songs/scraper.rb |
billboard_hot_100_songs-1.0.0 | lib/billboard_hot_100_songs/scraper.rb |