Class: Top100::BillboardScraper
- Inherits:
-
Object
- Object
- Top100::BillboardScraper
- Defined in:
- lib/top_100/billboard_scraper.rb
Instance Method Summary collapse
Instance Method Details
#scrape_from_artist_bio_page(url) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/top_100/billboard_scraper.rb', line 20 def scrape_from_artist_bio_page(url) html = open(url) bio = Nokogiri::HTML(html) artist = { name: bio.css('h1.title').text, location: bio.css('dl.facts > dd').text.split(" ")[0].strip, date: bio.css('dl.facts > dd').text.match(/\d+/)[0], } bio.css('aside.bio_sidebar').remove artist[:bio] = bio.css('article.bio_content').text.strip artist end |
#scrape_from_chart_page ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/top_100/billboard_scraper.rb', line 3 def scrape_from_chart_page html = open('http://www.billboard.com/charts/hot-100') nokogiri_object = Nokogiri::HTML(html) charts_array = Array.new nokogiri_object.css('div.chart-row__primary').each do |song| charts_array << { current_rank: song.css('span.chart-row__current-week').text, last_week_rank: song.css('span.chart-row__last-week').text, song_name: song.css('h2.chart-row__song').text, song_artist: song.css('a.chart-row__link').text.strip, artist_bio_link: song.css('a.chart-row__link').attribute('href').value + '/biography' } end charts_array end |