A quick perl script for used car research on craigslist
Wednesday, April 22nd, 2009So my 2001 VW jetta is getting a bit up there in the miles – it’s about 95k at the moment, and while this isn’t too much for a VW, I’ve been wanting to get a new car and I figure I should get rid of it while I can still feel good about selling it to someone else. Besides, I want to get a convertible – I live in southern California, and if it’s not the appropriate climate for one, I don’t know where is.
Initially I went to carmax and they offered me $2000. Yeeps! I was shocked. Could it really be worth that little? Kelly Blue book said it was at least worth $4k. So I thought I would test the open market and write a quick perl script to give me the average price for an item on craigslist. Here’s how it works and the code is below. It should be really easy to modify for anyone who could use something like this:
./cl_get_prices.pl 2001+jetta
http://losangeles.craigslist.org/search/cta?query=2001+jetta
lowest: 1200
highest: 9999
Average: 6134.48214285714
another example where I search for porsche boxster:
nick:~$ ./cl_get_prices.pl porsche+boxster
http://losangeles.craigslist.org/search/cta?query=porsche+boxster
lowest: 7600
highest: 33100
Average: 16865.6341463415
Anyway the code is below, and I’ll put a link to the actual perl script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/usr/bin/perl $wget="http://losangeles.craigslist.org/search/cta?query="; $wget .= $ARGV[0]; print $wget . "\n"; $html = `wget -q -O - $wget`; @words = split(' ', $html); foreach $word (@words) { if ( $word =~ m/^\$/) { $word =~ s/(\$|,)//g ; if ( $word =~ m/^\d+$/ ) { if ( $lowest eq '') { $lowest = $word ; } elsif ( $word < $lowest ) { $lowest = $word ; } if ( $highest eq '') { $highest = $word ; } elsif ( $word > $highest ) { $highest = $word ; } $amt += $word ; $count++; } } } $average = ( $amt / $count ) ; print "lowest:\t\t$lowest\nhighest:\t$highest\n"; print "Average:\t" . $average ."\n"; |
Here’s a link to the actual script you can download;. If you find it useful, let me know.