Getting average motorcycle price across all Craigslist cities

Today I’m going to look at a motorcycle that’s for sale on Craigslist. The asking price for the bike seems fair, but I wanted to get a sense for what other people were asking for the same model and year.

First I did a local search for the motorcycle I was interested in using the year, make and model search filters. The resultant URL was

https://philadelphia.craigslist.org/search/mcy?srchType=T&auto_make_model=suzuki+TU250X&min_auto_year=2012&max_auto_year=2012

This returned all the listings in Philadelphia for a 2012 Suzuki TU250X. The srchType=T parameter filters to only include results that have a match in the listing title.

Using pup, a command-line tool for parsing HTML, I extracted the asking price of the motorcycle in the search result listing.

curl -s "https://philadelphia.craigslist.org/search/mcy?srchType=T&auto_make_model=suzuki+TU250X&min_auto_year=2012&max_auto_year=2012" | \
pup 'ul.rows li.result-row p.result-info span.result-meta span.result-price text{}'

There is a CL page that lists every Craigslist site in the US. I parsed that for each location’s specific URL.

curl -s "https://geo.craigslist.org/iso/us" | \
pup 'div.geo-site-list-container a attr{href}'

I combined these

curl -s "https://geo.craigslist.org/iso/us" | \
pup 'div.geo-site-list-container a attr{href}' | \
while read location;
 do curl -s "$location/search/mcy?srchType=T&auto_make_model=suzuki+TU250X&min_auto_year=2012&max_auto_year=2012" | \
 pup 'ul.rows li.result-row p.result-info span.result-meta span.result-price text{}';
done

which outputs the asking prices…

$3800
$2750
$2800
$2950
$3800
$3750
$2800
$2400
$2750
$2950
$2750
$3800
$3750
$2700
$2400
...

I was then able to see how the price of the motorcycle in which I was interested compared to similar bikes throughout the US.