Last active
December 19, 2015 15:09
-
-
Save ZedThree/5974764 to your computer and use it in GitHub Desktop.
Calculates the area of a house from a listing on Zoopla
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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