Skip to content

Instantly share code, notes, and snippets.

@ZedThree
Last active December 19, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZedThree/5974764 to your computer and use it in GitHub Desktop.
Save ZedThree/5974764 to your computer and use it in GitHub Desktop.
Calculates the area of a house from a listing on Zoopla
import re
import urllib2
import numpy as np
from BeautifulSoup import BeautifulSoup
house_webpage = 'http://www.zoopla.co.uk/for-sale/details/28121543'
# Grab the whole webpage for the house listing
soup = BeautifulSoup(urllib2.urlopen(house_webpage).read())
# Pull out the "Property Description" bit
desc = soup.find("div",{"class":"top"}).text
# Find the room sizes and put them in an array
rooms = re.findall('\d\.\d\dm[ ]x[ ]\d.\d\dm',desc)
# Multiply the dimensions to get the area of each room
area = []
for room in rooms:
area.append( float(room.split()[0][:-1]) * float(room.split()[-1][:-1]) )
# Now add up all the room areas
total_area = np.array(area).sum()
# Print the total area to screen
print total_area
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment