Skip to content

Instantly share code, notes, and snippets.

@BruceHubbard
Created November 27, 2012 16:53
Show Gist options
  • Save BruceHubbard/4155441 to your computer and use it in GitHub Desktop.
Save BruceHubbard/4155441 to your computer and use it in GitHub Desktop.
Nokogiri Examples
Nokogiri::HTML.parse(open(url)).css('.tn a').collect {|img| img["href"]}
#open(url) - opens and returns an html document
#css('selector') is just like jquery except server side. It returns a (ruby equivalent of a) linq-like enumerable
#collect is the same as .NET's select function
#So this one line when I set url to a Craigslist listing detail page will open that page and return an array of images for that listing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment