Skip to content

Instantly share code, notes, and snippets.

@jqr
Created January 26, 2009 16:41
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 jqr/52861 to your computer and use it in GitHub Desktop.
Save jqr/52861 to your computer and use it in GitHub Desktop.
# Re: http://twitter.com/danielmorrison/status/1149336565
require 'rubygems'
require 'httparty'
require 'hpricot'
url = 'http://rubyonrails.org'
document = Hpricot.parse(HTTParty.get(url))
scrape = {
:title => 'head title',
:body => 'body'
}
values = {}
scrape.each do |name, selector|
text = (document / selector).inner_text.gsub(/\s+/, ' ')
values[name] =
if text.length > 300
text[0..300] + '...'
else
text
end
end
puts values.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment