Created
June 11, 2014 13:12
-
-
Save phil/1b8ea7d3e2aeb47ea928 to your computer and use it in GitHub Desktop.
Ruby Core Library Scraping Hackernews
This file contains 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
require "eventmachine" | |
require "em-http-request" | |
EventMachine.run do | |
sites = ["http://kyan.com"] * 20 | |
sites.each_with_index do |site,i| | |
http = EM::HttpRequest.new(site).get | |
http.callback do | |
# remove the site from the array | |
sites.pop | |
# Output some data about the site | |
puts "#{site} - #{i} - #{http.response_header.status}" | |
# Check to see if this was the last site and exit | |
EM.stop if sites.empty? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment