Skip to content

Instantly share code, notes, and snippets.

@chrislloyd
Created October 29, 2012 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislloyd/3974966 to your computer and use it in GitHub Desktop.
Save chrislloyd/3974966 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rest-client'
require 'nokogiri'
addresses = (1..10).inject([]) do |addresses, page|
$stderr.puts "fetching page #{page}"
html = RestClient.get 'http://mcserverlist.net/lists/top', params: {page: page}
doc = Nokogiri::HTML(html)
addresses += doc.css('.ip-and-port').map {|node| node.text.strip }
addresses
end
avg = addresses.inject(0) {|total, addr| total += addr.length } / addresses.length
puts avg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment