Created
June 18, 2018 11:38
-
-
Save pdabrowski6/84118aab9098bd6f7aabd450bfe02b76 to your computer and use it in GitHub Desktop.
The Ruby Rogues podcast - Hall of Fame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = {} | |
1.upto(20) do |page| | |
puts "page #{page}" | |
url = "https://devchat.tv/ruby-rogues/page/#{page}" | |
response = RestClient.get(url) | |
html = Nokogiri::HTML(response) | |
html.css("h3.entry-title a").map { |e| e[:href] }.each do |url| | |
response = RestClient.get(url) | |
html = Nokogiri::HTML(response) | |
title = html.css("h1.entry-title").text | |
views = html.xpath('//span[contains(@class, "td-nr-views")]').text.to_i | |
data[title] = views | |
end | |
end | |
def display_results(data) | |
puts "##############" | |
puts "## TOP 10 ##" | |
puts "##############" | |
data.sort_by { |k, v| v }.reverse.take(10).each_with_index do |e, index| | |
puts "#{index + 1}. #{e.first} - #{e.last} views" | |
end | |
end | |
display_results(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment