Skip to content

Instantly share code, notes, and snippets.

@phil
Created June 11, 2014 13:12
Show Gist options
  • Save phil/1b8ea7d3e2aeb47ea928 to your computer and use it in GitHub Desktop.
Save phil/1b8ea7d3e2aeb47ea928 to your computer and use it in GitHub Desktop.
Ruby Core Library Scraping Hackernews
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