So 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.
http://ghettocode.net/perl/CraigslistCarAverages
Sorry if this offends.
Hi,
I do not know how to use perl on win7 but I would like to find avg prices of certain items on CL. Could you please give me some direction on how I can use your cool script?
Thanks!
you can use active state perl. Once you install it, you should be able to run the script from the command line.
Hey Nick, I love the idea.
Care to chat over skype or googlechat? I’d love to pick your brain.
-Peace
Alex
how to you pass the second line into the script?
I am confused by your usage example as when i run a script i have to write
“perl perscript.pl”
seems like you just put down the directory and then pass a URL to the script?
@nate, yes that’s exactly it. You would save it somewhere, get to a command prompt, and execute the command: “perl /path/to/script search+term url”
@alex, you’re welcome to email me at my first name at the website’s domain if you’ve got a question.