Scrape Craigslist for Posts
.
gem install craigslister
gem 'craigslister'
require 'craigslister'
client = Craigslister.new(
item: 'Couch',
area: 'austin', # optional (defaults to 'sfbay')
section: 'mca', # optional (defaults to 'sss')
low: 500, # optional
high: 2000, # optional
)
The area
and section
parameters must be valid Craigslist url query strings.
Area | Query |
---|---|
SF bay area | 'sfbay' |
austin | 'austin' |
mendincino county | 'mendocino' |
Section | Query |
---|---|
motorcycles | 'mca' |
cars & trucks | 'cta' |
appliances | 'ppa' |
If you are unsure of what your local area
query param may be it can be found in the browser when you navigate to craigslist, the same can be done with section
. 'https://sfbay.craigslist.org/search/cta?query=chevy%20chevelle'
. Here 'sfbay'
would be the area (SF bay area), and 'cta'
would be the section (cars & trucks).
Post
objects are instantiated with the data scraped from a single page of a Craigslist post.
# Post objects are instantiated with the data scraped from a single posting on Craigslist
couches = client.posts
# They have various attributes containing relevant post data
couch = couches[0]
couch.title
couch.image
couch.price
couch.location
couch.url
couch.description