Skip to content

Instantly share code, notes, and snippets.

@fowlmouth
Created April 21, 2013 01:31
Show Gist options
  • Save fowlmouth/5428113 to your computer and use it in GitHub Desktop.
Save fowlmouth/5428113 to your computer and use it in GitHub Desktop.
require'open-uri'
require'nokogiri'
URL = 'http://%{city}.craigslist.org/search/%{section}?zoomToPosting=&query=%{query}&srchType=T&minAsk=&maxAsk='
Entry = Struct.new(:name, :link, :age, :location)
def get(opts={})
opts = {
query: 'w4m', city: 'stlouis',
section: 'cas'
}.merge opts
open(URL%opts, &:read)
end
def pars(opts={})
Nokogiri::HTML(get(opts)).css('.srch.row').map { |r|
link = r.css('.title1 a')[0]
name = link.children.first.to_s
link = link.attributes["href"].value
age = r.css('.title2 .itempnr')[0].children
loc = age[3].text rescue "None"
age = age[1].text rescue "None"
age = age.to_i if age.to_i != 0
Entry.new(name, link, age, loc)
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment