5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/billboard_hot_100_songs/scraper.rb', line 5
def self.scrape_main_page
page_data = Nokogiri::HTML(open(BASE_PATH))
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
|