Auto mailer for

August 3, 2012

I still don’t have an apartment of my own in Stockholm, and checking out (equivalent to craigslist) every five minutes is a bit tedious.
My solution to this is something, you could argue, should be a part of blocket’s services.

I’ve built a small php scraper (because they don’t give out RSS feeds), that fetches the blocket page which I’m interested in (blocket listings), scrapes out all the latest listings, inserts them into a database (for later reference), and the last thing the script will do, is mail me with the details about the newest items.

Why do I insert them into a database if I’m forwarding them through mail? Because if I don’t, I won’t have any idea of which listings are new and which are old.

To handle the scraping I’ve use the simple HTML dom parser¬†library, which worked great.

If you wan’t to deploy your own version, I’ve included full documented source code below. The script isn’t beautiful by any means, but it’ll do the job. Don’t forget to add the script in your crontab, so it’ll automatically run.

Remember that doing scraping is generally bad practice and should be used sparsely, I decided to do this because this should’ve been included in’s basic functionality,¬†or that’s at least my reasoning for it.

Download the sourcecode! (