Using spareroom efficiently

May 5, 2011 at 1:24 am Leave a comment

I find searching sites like gumtree, craigslist or spareroom irritating, the main problem I get is that I end up wasting time clicking through results that I’ve seen before and generally browsing around. This is partly due to my ineffectualness, but also do with the layout of the site. Things become particularly annoying if you visit the site frequently.

What I really want is a means to consider each listing once and only once – some sites might be quite good at doing this – by giving you e-mail updates and such like – but I couldn’t easily see a way of making this work.

Dirty hacks to the rescue:

I wrote the following scraper which will perform a search for me and print out a list of urls

# Write-once code - do not pass judgment
import urllib
from lxml.etree import HTML
URL = ""

def mangle_urls(urls):
    new_matches = list(set([url.split('&', 1)[0] for url in urls]))
    return new_matches

stream = urllib.urlopen(URL)
new_url = stream.url
page =
tree = HTML(page)
matches = mangle_urls(tree.xpath('//a[contains("More info", text())]/@href'))
matches_so_far = set(matches)
for offset in range(10, 300, 10):
    url = new_url + 'offset=%d' % offset
    page = urllib.urlopen(url).read()
    tree = HTML(page)
    new_matches = mangle_urls(tree.xpath('//a[contains("More info", text())]/@href'))
    new_matches = set(new_matches) - matches_so_far
    matches_so_far |= set(new_matches)
    matches += list(new_matches)
matches = ['' + url for url in matches if not url.startswith('http')]
print '\n'.join(matches)

I then took the output saved it to ‘new_rooms’. With vim and some macro magic, I then went through links one at a time, considering them, possibly sending replies, and then moving the links to and ‘already_considered’ file. Using command line magic I was then able to ensure that the next time I got a list of links I could remove the links I’d already considered.

Not quite sure if this quite justified the time invested, but it’s coming pretty close. If this script still works when you read this post it could just be worth your time using the script (since you don’t have to write it.)

Kind regards,


Entry filed under: Uncategorized.

Templating in make: parameterised targets Wifi tethering out of the box on gingerbread without root

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

May 2011
« Apr   Jun »

%d bloggers like this: